I've create a JFrame named homeWindowFrame and set its size to (600, 500) and then I added a JPanel named mainContainerPanel to the JFrame. I set a new size to JPanel but it's not working. JPanel size is remaining same as that of JFrame instead of updating. How can I set size to JPanels in a JFrame.Thanks in advance. Here my code:
/** * Main window construction */
JFrame homeWindowFrame = new JFrame("Home - Crime File Management System");
if (isInvalidLogin) {
homeWindowFrame.setSize(600, 500);
} else {
homeWindowFrame.setSize(600, 400);
}
homeWindowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
homeWindowFrame.setLocation((screenSize.width / 2) - (homeWindowFrame.getWidth() / 2), (screenSize.height / 2) - (homeWindowFrame.getHeight() / 2));
/**
* Main panel construction
*/
JPanel mainContainerPanel;
if (isInvalidLogin) {
mainContainerPanel = new JPanel(new GridLayout(4, 2));
} else {
mainContainerPanel = new JPanel(new GridLayout(3, 2));
}
homeWindowFrame.add(mainContainerPanel);