I am currently having a problem with my Frame. I am trying to add a panel into a Frame, but instead it opens two different windows, how can I fix that? I want the button and panel to be in the frame.
public class MenuSample extends JFrame{
Panel and Button that open up in a different window
private JButton button;
private JPanel panel;
public MenuSample () {
Frame testFrame = new Frame("Test Frame");
testFrame.addWindowListener(new WindowAdapter () {
public void windowClosing (final WindowEvent e)
{
System.exit(0);
}
});
testFrame.setMenuBar(this.getMenubar());
testFrame.setSize(500,300);
testFrame.setLocation(400,300);
testFrame.setVisible(true);
Panel and Button that are supposed to be in the Frame
panel = new JPanel(new GridLayout(1,1));
button = new JButton("erster Button");
panel.add(button);
getContentPane().add(panel);
pack();
setVisible(true);
}
protected MenuBar getMenubar () {
some irrelevant MenuBar stuff
menuLeiste.add(...);
return menuLeiste;
}
}