I have a JPanel
called parentPanel
.
Also I have other sonPanels
in parentPanel
.
I want to remove the sonPanels
and add them in an arraylist<JPanel>
Can you help me??
Thanks开发者_JAVA百科 in advance!!! :)
Since JPanel inherits from Container, you can use the getComponents() method to get the list of your sonPanels.
After getting them all, you can clear you parentPanel by calling the removeAll() method.
If you had a deleteRows
method, simply call the first method on your JPanel
, lets call it contentPane
, and then call the second method to remove.
public Component[] getAndClearSonPanels() {
Component[] currentComponents = contentPane.getComponents();
contentPane.removeAll();
return currentComponents;
}
If you need to traverse even more deeply into each of the JPanels, you would need to, recursively do so.
精彩评论