So i have a frame and 2 panels, originally panel A is displayed in the frame. i have got it set up so when a button is clicked in the panel it makes a call back to the frame and runs this bit of code. (“splash” is the panel that is originally displayed and “game” is the panel i want to show after the button press)
public void startGame()
{
System.out.println("starting game");
remove(splash);
gameThread = new Thread(game, "game thread");
gameThread.start();
add(game);
/*
this.setSize(0,0);
this.setSize(450, 450);
*/
}
anyways this seems to remove the one panel fine but wont display the second panel until you resize the window. the commented section seems to solve this problem but i cant help think there is a better way to do this. i have surfed the API and haven’t found anything helpful.
if anyone knows a better way, or has run into this problem. please share your knowledge, this one has me stumped.
As Michael pointed out CardLayout is a good way to go.
The specific functionality you are looking for is Container.validate(). It will “cause the container to lay out its subcomponents again. It should be invoked when this container’s subcomponents are modified … after the container has been displayed.”