When I create my GUI, I use cardlayout to store different panels, as I am sure many people know. This sets my screen to the width and height of the largest panel. This causes problems with the aesthetics of my first screens, which are much smaller than SudokuPanel and CalkuroPanel .
I tried to set my preferred size when I switch to large screens, but to no avail.
Any help with links to good information or anything that would just be generally useful would be greatly appreciated :).
Please find my main class (where I draw the GUI) below:
import java.awt.*; import javax.swing.*; import java.util.*; public class puzzleGUI{ private static JPanel screens; public static String username; static public void main (String[] args){ JFrame puzzle = new JFrame ("Sudoku/Calkuro Pro"); ... PuzzleStartPanel startPanel = new PuzzleStartPanel(); PuzzleChoosePanel choosePanel = new PuzzleChoosePanel(); PuzzleSudokuPanel sudokuPanel = new PuzzleSudokuPanel(); PuzzleCalkuroPanel calkuroPanel = new PuzzleCalkuroPanel(); screens = new JPanel(new CardLayout()); screens.add(startPanel, "start"); screens.add(choosePanel, "choosePuzzle"); screens.add(sudokuPanel, "sudoku"); screens.add(calkuroPanel, "calkuro"); screens.setPreferredSize (new Dimension(250, 80)); puzzle.setJMenuBar(menuBar); puzzle.getContentPane().add(screens); puzzle.pack(); puzzle.setVisible(true); puzzle.setResizable(false); puzzle.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); } static public void getUsername(String str){ username = str; } static public void openWindow(String newFrame){ CardLayout cl = (CardLayout)(screens.getLayout()); cl.show(screens, newFrame); } }
Edit
brainblast tried to pack the frame after resetting the preferred size when calling openWindow and wolah, new frame size: D
static public void openWindow(String newFrame, int a, int b){ CardLayout cl = (CardLayout)(screens.getLayout()); cl.show(screens, newFrame); screens.setPreferredSize (new Dimension(a, b)); puzzle.pack(); }
source share