#remove() doesn't delete JPanel in jswing

7 messages · Page 1 of 1 (latest)

copper dagger
#

I am trying to delete and add JPanels through code but when I delete a panel with remove() nothing happens.

boreal thistleBOT
#

This post has been reserved for your question.

Hey @copper dagger! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

copper dagger
#
JPanel currentJPanel = panel.getOrderLinePanel();
            
currentJPanel.removeAll();
orderLinePanels.remove(panel);
remove(currentJPanel);
revalidate();
repaint();
#

I have checked the ID of the JPanel which gets assisgned to currentJPanel and it is the same as the one I am trying to delete. removeAll() works but the remove() does nothing.

sonic nebula
#

From a code wise perspective everything should work as expected (assuming that this code is inside a class that JComponent). Are you sure that the panel isn't getting deleted ? You can check the component count of the container by using getComponentCount().
Does the number of components change ?

white marten