Hallo zusammen!
Bei mir versteckt sich das JMenu unter dem JPanel (siehe Bild)
Das ganze ist ein JFrame, darauf ist ein JLayeredPane, auf dem alle Componenten drauf sind.
Mit setJMenuBar ist das Menü auf dem JFrame drauf.
Das Schwarze, was das Menü verdeckt, ist ein JLayeredPane, dass erst nach einem Methodenaufruf dem content-JLayeredPane hinzugefügt wird.
Bei mir versteckt sich das JMenu unter dem JPanel (siehe Bild)
Das ganze ist ein JFrame, darauf ist ein JLayeredPane, auf dem alle Componenten drauf sind.
Mit setJMenuBar ist das Menü auf dem JFrame drauf.
Das Schwarze, was das Menü verdeckt, ist ein JLayeredPane, dass erst nach einem Methodenaufruf dem content-JLayeredPane hinzugefügt wird.
Java:
public class ESTW_Developer extends JFrame
{
private JLayeredPane contentPanel;
private JDialog estw_daten;
private JDialog lupen_daten;
// Menu-Leiste:
private JMenuItem Neu;
private JMenuItem Oeffnen;
private JMenuItem Speichern;
private JMenuItem Speichern_unter;
private JMenuItem Beenden;
private JMenuItem Eigenschaften;
private JMenuItem Lupe_einfuegen;
// Funktionen:
private boolean geladen;
private boolean editiert;
// Geladene Datei:
private String Datei = "";
// Felder im Standard-Fenster:
private JLabel lupenname;
// Lupenscroller:
private JScrollPane lupenscroller;
private JPanel lupenpanel;
public static void main(String[] args) throws IOException
{
new ESTW_Developer();
}
public ESTW_Developer()
{
super("ESTW-Developer");
contentPanel = new JLayeredPane();
add(contentPanel);
getContentPane().setBackground(Color.LIGHT_GRAY);
setBackground(Color.LIGHT_GRAY);
contentPanel.setBackground(Color.LIGHT_GRAY);
contentPanel.setLayout(null);
setLocation(0,0);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
Object[] options = { "Ja", "Nein"};
int antwort = (JOptionPane.showOptionDialog(null, "Möchten Sie das Programm wirklich beenden?", "Warnung", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]));
if (antwort == 0)
{
System.exit(1);
}
}
});
JMenuBar menuBar = new JMenuBar();
JMenu Datei = new JMenu("Datei");
JMenu Bearbeiten = new JMenu("Bearbeiten");
JMenu Einfuegen = new JMenu("Einfügen");
JMenu Hilfe = new JMenu("Hilfe");
Neu = new JMenuItem("Neu");
Neu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (geladen)
{
Object[] options = { "Ja", "Nein"};
int antwort = (JOptionPane.showOptionDialog(null, "Möchten Sie wirklich ein neues ESTW erstellen?", "Warnung", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]));
if (antwort == 0)
{
name = "";
kuerzel = "";
ESTW_Daten();
}
}
else
{
ESTW_Daten();
}
}
});
Oeffnen = new JMenuItem("Öffnen");
Oeffnen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (geladen)
{
Object[] options = { "Ja", "Nein"};
int antwort = (JOptionPane.showOptionDialog(null, "Möchten Sie wirklich ein anderes ESTW öffnen?", "Warnung", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]));
if (antwort == 0)
{
name = "";
kuerzel = "";
Oeffnen();
}
}
else
{
Oeffnen();
}
}
});
Speichern = new JMenuItem("Speichern");
Speichern.setEnabled(false);
Speichern.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Speichern();
}
});
Speichern_unter = new JMenuItem("Speichern unter");
Speichern_unter.setEnabled(false);
Speichern_unter.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Speichern_unter();
}
});
Beenden = new JMenuItem("Beenden");
Beenden.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Object[] options = { "Ja", "Nein"};
int antwort = (JOptionPane.showOptionDialog(null, "Möchten Sie das Programm wirklich beenden?", "Warnung", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]));
if (antwort == 0)
{
System.exit(1);
}
}
});
Datei.add(Neu);
Datei.addSeparator();
Datei.add(Oeffnen);
Datei.add(Speichern);
Datei.add(Speichern_unter);
Datei.addSeparator();
Datei.add(Beenden);
Eigenschaften = new JMenuItem("Eigenschaften");
Eigenschaften.setEnabled(false);
Eigenschaften.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ESTW_Daten();
}
});
Bearbeiten.add(Eigenschaften);
Lupe_einfuegen = new JMenuItem("Lupe einfügen");
Lupe_einfuegen.setEnabled(false);
Lupe_einfuegen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
lupe_dat.setText("");
//if (selectedLupe != null)
// contentPanel.remove(selectedLupe);
//selectedLupe = null;
//lupenname.setText("");
editLupe = false;
EditLupe();
}
});
Einfuegen.add(Lupe_einfuegen);
menuBar.add(Datei);
menuBar.add(Bearbeiten);
menuBar.add(Einfuegen);
menuBar.add(Hilfe);
setJMenuBar(menuBar);
lupenname = new JLabel();
lupenname.setSize(200,20);
lupenname.setLocation(420, 600);
lupenname.setVisible(true);
lupenname.setHorizontalAlignment(SwingConstants.CENTER);
contentPanel.add(lupenname);
lupenpanel = new JPanel();
lupenscroller = new JScrollPane(lupenpanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
lupenscroller.setSize(1030, 85);
lupenscroller.setLocation(2, 650);
lupenscroller.setVisible(false);
contentPanel.add(lupenscroller);
pack();
setSize(1050, 800);
}
public void selectLupe(LUPE lup)
{
if (selectedLupe != null)
{
contentPanel.add(lup, JLayeredPane.DEFAULT_LAYER);
lupenname.setText("L_" + lup.holeName());
}
}
}
public class LUPE extends JLayeredPane
{
public LUPE()
{
setSize(1020,528);
setLocation(7,60);
setVisible(true);
setForeground(Color.BLACK);
// Erstellen der Linien (entfernt)
Canvas black = new Canvas()
{
public void paint(Graphics g)
{
g.setColor(Color.BLACK);
g.fillRect(0,0,1020,528);
}
};
black.setLocation(0,0);
black.setSize(1020,528);
black.setVisible(true);
add(black, JLayeredPane.DEFAULT_LAYER);
validate();
}
}