I have a problem that my frame becomes quite small when calling the frame.pack-method. code below:
public class ManagementView extends JFrame{
private CardLayout cl;
private JPanel panel;
private MainlandingPanel mainLandingPanel;
private MasterViewPanel masterViewPanel;
ManagementView() {
masterViewPanel = new MasterViewPanel();
mainLandingPanel = new MainLandingPanel();
cl = new CardLayout();
panel = new JPanel(cl);
panel.setSize(1100, 770);
panel.add(mainLandingPanel, "Home");
panel.add(masterViewPanel, "MasterView");
//Create the main Frame
this.setTitle("Hello World");
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setContentPane(panel);
this.pack();
this.setVisible(true);
cl.show(panel, "Home");
}
}
Both MasterViewPanel and MainLandingPanel have a null Layout, but the member called panel has a given size, in wich i have added a CardLayout, containing the other two panels. I call frame.pack() expecting it to be 1100 x 770, but instead i only get an empty window.
What am i doing wrong? (Yes i do understand that not using a LayoutManager is not recommended, but i just can't understand how that works when designing more complex panels.)