3

Okay currently I am trying to make a multi-window program.

And from seeing other forums, it seems for you to do that in Java JFrame you must update its content pane by adding the new JComponent(new window/layout/idk), set the current window visibility to false, set the new one visibility to true and validate &/ repaint content pane:

    contentPane.add(newWindowPanel);
    currentWindowPanel.setVisible(false);
    newWindowPanel.setVisible(true);
    contentPane.validate();
    contentPane.repaint();

now, what I am trying to do and partially have done is created a class that extends JPanel, and this class stands to be the top of an hierarchy for many other JPanel classes that I am going to create.

Within that class I have this method :

    public void updateContentPane(Container contentPane, JPanel currentPanel, JPanel nextPanel){

    contentPane.add(nextPanel);
    currentPanel.setVisible(false);
    nextPanel.setVisible(true);
    contentPane.validate();
    contentPane.repaint();
} 

When I call this method within one of the child classes, it doesn't work.

    updateContentPane(WindowMain.contentPane, this, mainMenuClass);

Each of the child class inherits the JPanel characteristic.

"WindowMain" is a class that extends JFrame, and "contentPane" is a static container variable that holds the frame contentPane.

"this" represents the current class (inherits JPane), but "this" don't actually work new Object() works.

"mainMenuClass" also inherits JPanel and has already been instantiated in this class.

My goal is to simply jump from one scene to the other by calling that method. But it goes through the code (debug) but nothing happens. But, if I take the code within the method and place it inside a button listener it works fine.

(Sorry for all this writing, it will probably bring some confusion at that, but I need to figure this out nonetheless, and I will set condition for when the contentPane already contains a class, so no need to mention it)

Seb D.
  • 5,046
  • 1
  • 28
  • 36
Chuck
  • 75
  • 1
  • 2
  • 10

1 Answers1

2

You could just update the whole frame by doing

frame.revalidate();
frame.repaint();
nick zoum
  • 7,216
  • 7
  • 36
  • 80
  • 1
    That doesn't help, it runs through the code but it doesn't update it. I will debug the code to find out if the content pane is updating – Chuck Jul 20 '16 at 22:06