hi, can i create a button in gwt that onClick stays pressed and if it looks pressed onClick releases it? and the button has a different styles in each state?
any idea?
hi, can i create a button in gwt that onClick stays pressed and if it looks pressed onClick releases it? and the button has a different styles in each state?
any idea?
This is a pretty basic approach that should give you the toggle that you want. Basically the first click will put a 'clicked style' that you've created that will give the thing the look you want for when it looks pressed. Clicking it a second time will revert back to your normal button style so it will look not pressed again.
final Button button = new Button();
button.setStyleName("NormalButtonStyle");
button.addClickHandler( new ClickHandler() {
private boolean clickedStyle = false;
public void onClick( final ClickEvent clickEvent ){
clickedStyle = !clickedStyle;
if( clickedStyle ){
button.setStyleName("ClickedButtonStyle");
}
else {
button.setStyleName("NormalButtonStyle");
}
}
});