JPanel issue

Hi,

I have a JScrollPanel which contains & displays an array of JPanels fine.

JScrollPanel-->Array of JPanels

My problem is is that when I click on one of these JPanels (the scroll panel is a grid layout, 5 x 4) I need it to change to another JPanel. I cannot get this to work, I can only get the panel to disappear by looking to see which JPanel the mouse was clicked in and calling remove(panelArray[i]);

.

I have tried changing the value of the jpanel which was clicked, to the new jpanel, but that doesn't work. I'm not very experienced with swing and am wondering what I could do.

Thanks.

Message was edited by:

kerryblue19

[693 byte] By [kerryblue19a] at [2007-11-27 8:52:58]
# 1
After you add or remove a component from a panel you need to revalidate() the panel.
camickra at 2007-7-12 21:09:32 > top of Java-index,Desktop,Core GUI APIs...
# 2
thank you so much, it works perfectly now! could you explain revalidate though so I can understand it properly? does it just cycle through the panels and check to see if they are the same, and if not redraws them?
kerryblue19a at 2007-7-12 21:09:32 > top of Java-index,Desktop,Core GUI APIs...
# 3
Basically you are just invoking the LayoutManager so all the components can be layed out again correctly. I should add that sometimes you also need to add a repaint() just to make sure the components get painted in their new positions.
camickra at 2007-7-12 21:09:32 > top of Java-index,Desktop,Core GUI APIs...
# 4
thanks for the help!
kerryblue19a at 2007-7-12 21:09:32 > top of Java-index,Desktop,Core GUI APIs...