PDA

View Full Version : change buttons on ButtonBar dynamically



avb
19 Oct 2008, 1:51 AM
Hello!

I faced with the following problem:

1. I have a FormPanel with a ButtonBar. By default, all fields in this panel are disabled and ButtonBar contains two buttons: OK, EDIT. If a person clicks the EDIT button, all fields should become enabled and ButtonBar should contain other buttons: SAVE, CANCEL. The problem is that new buttons don't appear. I do the following:

ButtonBar bar = formPanel.getButtonBar();
buttonBar.removeAll();
buttonBar.add(saveButton);
buttonBar.add(cancelButton);
formPanel.layout();

However, all buttons are disappeared and new are not shown.
Similarly, I can't add new button to the existing ButtonBar.

Could you please help me to solve it? Now I use silly workaround: set my "edit" flag to true, remove and add this FormPanel, rendering it with proper buttons! It is rediculous! :)

Thank you!

gslender
19 Oct 2008, 2:34 AM
try calling .layout() on the buttonbar


cheers,
grant

avb
19 Oct 2008, 2:41 AM
grant,

I tried, but the problem is that layout() method in ButtonBar is protected! :) As far as I understand, it is called from onRender() method in ButtonBar.

And at this point another question arises: how can I force re-render of the components? Because during the rendering so many useful things happen! I want to reproduce them by demand! :)

avb
20 Oct 2008, 4:36 AM
So, it means that it is impossible to change buttons dynamically??
Why don't you call layout() in methods like add(Button)? Or make layout() public?

Eh..

amundb
20 Oct 2008, 7:53 AM
You should add all of the buttons to the button bar upon creation. Then just call setVisible(false) on the ones you do not wish to show right away. When it come time for them to appear on the bar, just setVisible(true)

avb
20 Oct 2008, 8:32 PM
Thanks for advice! I think it is a solution. :)