Despot Despondency
July 13th, 2008, 05:00 PM
Hey. I'm having a problem refreshing a JFrame when clearing the contentPane and then adding a new JPanel to it. I've got a JFrame and when I clear the contentPane, with removeAll(), and then add a new JPanel I have to minimize the window and then enlarge it before the changes take affect. Here's the code
package gui;
import javax.swing.JFrame;
public class Interface extends JFrame{
private static final long serialVersionUID = 1L;
private static JFrame frame;
public Interface(){
frame = new JFrame("Risk");
createAndShowGUI();
}
private static void createAndShowGUI(){
FrameUtil.setUp(frame);
frame.setVisible(true);
}
public static void MainMenu(){
frame.getContentPane().removeAll();
MenuPanel menu = new MenuPanel();
frame.setContentPane(menu.getPanel());
}
public static void NewGameMenu(){
frame.getContentPane().removeAll();
NewGamePanel newGamePanel = new NewGamePanel();
frame.setContentPane(newGamePanel.getPanel());
}
}
Any suggestions?
package gui;
import javax.swing.JFrame;
public class Interface extends JFrame{
private static final long serialVersionUID = 1L;
private static JFrame frame;
public Interface(){
frame = new JFrame("Risk");
createAndShowGUI();
}
private static void createAndShowGUI(){
FrameUtil.setUp(frame);
frame.setVisible(true);
}
public static void MainMenu(){
frame.getContentPane().removeAll();
MenuPanel menu = new MenuPanel();
frame.setContentPane(menu.getPanel());
}
public static void NewGameMenu(){
frame.getContentPane().removeAll();
NewGamePanel newGamePanel = new NewGamePanel();
frame.setContentPane(newGamePanel.getPanel());
}
}
Any suggestions?