I am writing a simple game withing which I am using a JFrame which contains a grid and a JPanel.
Here is my pseudo code:
void MyJframeConstructor()
{
// some basic bootstrap logic
// calling repaint to draw grid
repaint();
// Grid is drawn fine.
// Showing user a confirm dialog box on which I add below JPanel.
if(confirmed)
{
// GameInfoPanel extends JPanel.
infoPanel = new GameInfoPanel(new FlowLayout(FlowLayout.LEFT));
infoPanel.setPreferredSize(new Dimension(400, 100));
infoPanel.setLocation(500, 50);
this.add(infoPanel);
infoPanel.validate();
}
}
My problem here is my JFrame or window is 480 x 680.
Within this I am drawing a grid in 480 x 480 area.
Below which I want the JPanel to be located at 500,50 with dimension 400, 100.
However, when I run this code, once the user confirms with OK, the JPanel fills up the entire JFrame.
How can I keep the panel in its location and consistent in size through out the life of the app ?
Any help is highly appreciated and thanks in advance.