2

I am using com.jgoodies.forms.builder.PanelBuilder to add Buttons and rows. Then I call PanelBuilder.getPanel() and attach the panel to a JPopupMenu.

Is there a way to remove and reattach some of the attached components from the Panel that PanelBuilder has produced: I want to blend in/out one of the attached Buttons dynamically and the corresponding empty row (added with PanelBuilder.appendRow("f:30px")).

Thanks.

Riduidel
  • 22,052
  • 14
  • 85
  • 185
d56
  • 825
  • 1
  • 9
  • 26

2 Answers2

2

Removing the component does work but it leaves area of unused space on the panel. JPanel.revalidate() works only when PanelBuilder.appendRow() was not used before adding JButton.

Also, I couldn't reattach removed JButton. It appears in the component list of JPanel but is not being displayed.

That's why I went to create a new JPanel dynamically on every request and assigning it to the JPopupMenu.

d56
  • 825
  • 1
  • 9
  • 26
0

If you have ketp references to the initial item, there is nothing that prevents you from doing a

myPanel.remove(theComponent);
Riduidel
  • 22,052
  • 14
  • 85
  • 185
  • But then the Panel's height is not updated. I see a wide empty line at the last index where the component was before. How do i deal with PanelBuilder.appendRow("f:30px") that was added before the Button that is needed no more after the Button is removed? – d56 Jul 20 '10 at 15:57
  • 1
    try doing panel.pack() or validate().. or have two panels in the same location and use the setvisible() method of the panel – harshit Jul 20 '10 at 16:04