views:

24

answers:

2

Hi,

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.

A: 

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

myPanel.remove(theComponent);
Riduidel
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
try doing panel.pack() or validate().. or have two panels in the same location and use the setvisible() method of the panel
harshit
A: 

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
Don't forget to select one of the answers as the correct one by clicking the check beside one of these replies.
Riduidel
What do i do if none of the answers really solved my problem?
d56