public SimpleToggleButtonSample() {
HorizontalPanel buttons = new HorizontalPanel();
final SimpleToggleButton button = new SimpleToggleButton("Toggle Button");
button.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
showMessage(button.isDown() ? "Button is down" : "Button is up");
}
});
button.getDownFace().setText("Toggle Button (down)");
buttons.add(button);
addGap(buttons, "10px");
final SimpleToggleButton iconButton = new SimpleToggleButton("Icon Toggle Button", WidgetImages.Instance.get().icon_Printer().createImage());
iconButton.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
showMessage(iconButton.isDown() ? "Button is down" : "Button is up");
}
});
buttons.add(iconButton);
addGap(buttons, "10px");
final SimpleToggleButton customButton = new SimpleToggleButton("Toggle Button Custom Width", WidgetImages.Instance.get().icon_Printer().createImage());
customButton.setWidth("250px");
customButton.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
showMessage(customButton.isDown() ? "Button is down" : "Button is up");
}
});
buttons.add(customButton);
addGap(buttons, "10px");
SimpleToggleButton disabledButton = new SimpleToggleButton("Disabled Toggle Button", WidgetImages.Instance.get().icon_CubeGreen().createImage());
disabledButton.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
showMessage("Show never be shown");
}
});
disabledButton.setEnabled(false);
buttons.add(disabledButton);
addGap(buttons, "10px");
SimpleToggleButton group1Button= new SimpleToggleButton("Group 1", WidgetImages.Instance.get().icon_CubeGreen().createImage());
group1Button.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
showMessage("Group 1 was clicked");
}
});
group1Button.setGroup("group");
buttons.add(group1Button);
addGap(buttons, "10px");
SimpleToggleButton group2Button= new SimpleToggleButton("Group 2", WidgetImages.Instance.get().icon_CubeGreen().createImage());
group2Button.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
showMessage("Group 2 was clicked");
}
});
group2Button.setGroup("group");
buttons.add(group2Button);
VerticalPanel main = new VerticalPanel();
main.add(buttons);