PDA

View Full Version : Custon align in ButtonBar



listirer
27 Feb 2012, 8:31 PM
In the ButtonBar of a Windows I would have a custom align: a Status align to left and the buttons align to right.

This code align all the components to the right:


Status status = new Status();
status.setAutoWidth(true);
super.getButtonBar().add(status);

super.setButtonAlign(Style.HorizontalAlignment.RIGHT);

Button saveButton = new Button("Save",
new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
save();
}
});
super.addButton(saveButton);

Button close = new Button("Close",
new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
hide();
}
});
super.addButton(close);

Joshua093
27 Feb 2012, 11:23 PM
I believe that I have done something similar to what you are looking for in a few different situations, but none of them are very intuitive.The easiest produces the following results:
32188

I have modified the button bar through some simple CSS to fit the needs of our users (I know... it's ugly).To get this to display the way I wanted, and for performance reasons, I am using an HTML container and adding my code through this.

Without completely gutting my code I can give you a few snippets so you can see exactly what I'm doing.This code creates the HTML container and calls another class to build my header with the widget attached


HtmlContainer hc = new HtmlContainer();
hc.setHtml(HtmlHelper.createHeaderWithWidget("Rating Factors", "myButtonBar"));
hc.add(myButtonBar, "#myButtonBar");
hc.setId("mySectionHeaderWithButtonBar");
add(hc);

The code that creates the header is here: (Because of some serious formatting issues when submitting I have attached a picture instead, which indeed causes MORE formatting issues... sorry.)

32189


That seems fairly simple, and indeed it is. There are a few things that I had to do in order to get the alignment correct for my application which are:
myButtonBar.setAlignment(HorizontalAlignment.RIGHT);
myButtonBar.setStyleAttribute("float", "right");

I am certain that this could have been done more elegantly using more GXT widgets and layouts, but for my application they created unnecessary overhead that I could avoid easily enough. (We have roughly 10 of these on each screen, some with widgets and some without.)

listirer
27 Mar 2012, 12:54 AM
Thanks for the reply, I hoped in a simplest solution (via Java code).