Swing pannels visibility

Hi,



I am using Swing controls + JME, i have a border layout, where the center is the 3D window, and the rest are 2D JPanels.

It runs fine, but when i attach or remove JPanels and need to resize the main window to be able to see the panels changes.

I tryed doing .dolayout(), repaint(), etc… but nothing runs, i need to resize the window.

I am not using the SwingUtilities thread.



Can someone point me how to update the visibility of my Panels?



Thanks.


Try revalidate() on the container with the BorderLayout after you add your panels:


mainPanel.add(jmeView, BorderLayout.CENTER);
mainPanel.add(leftPanel, BorderLayout.WEST);
mainPanel.revalidate();


This should work if I understood you correctly.

I am building the app on top of SimpleJMEApplet.



this.add(propietatsPanel, BorderLayout.EAST);

this.add(interfacePanel, BorderLayout.SOUTH);

       

this.resize(800, 600);





The 3D canvas automatically is placed on Borderlayout.Center.

I can't find the way to get the main contentPane to call the .revalidate() as you says.

Hmm, not sure if it will work for an applet, but you can always try by inserting a JPanel containing your other Components as the only child of your SimpleJMEApplet:


JPanel rootPanel = new JPanel();
rootPanel.setLayout(new BorderLayout());
this.add(rootPanel);
rootPanel.add(myJMEView);
rootPanel.add(propietatsPanel, BorderLayout.EAST);
rootPanel.add(interfacePanel, BorderLayout.SOUTH);
rootPanel.revalidate();

i tryed that, but i don't know how to find the myJMEView to insert manually to the new container.

Jordi Perez said:

i don't know how to find the myJMEView

That would be your 3D canvas you are referring to here:
Jordi Perez said:

The 3D canvas automatically is placed on Borderlayout.Center.

Sorry for not being clear enough about that.

I am doing:



JPanel rootPanel = new JPanel();

rootPanel.setLayout(new BorderLayout());

this.add(rootPanel);

rootPanel.add(myJMEView);

rootPanel.add(propietatsPanel, BorderLayout.EAST);

rootPanel.add(interfacePanel, BorderLayout.SOUTH);

rootPanel.revalidate();



where myJMEView is the LWJGLCanvas (obtained with (Canvas)this.getComponent(0))



Doing this, myJMEView in not created.





I tryed another way:



i do: this.validate() ( the SimpleJMEApplet class has no revalidate() method), without creating the top panel as you said.

        With that runs ok, except that the new Panel atached is flickering, if i move the main window or i resize it, it leaves the flickering and appears solid.

        Now i don't know how to avoid the flickring.

After cleaning my code, the problems with the panels seems to be all arranged.



When inserting/removing new panels i call .validate() on the main container, and .repaint() on the added panel container, this way runs fine, and my flickers have dissapeared… nice