public class Button extends Label
This example shows a simple button:
Button button = new Button("Press Me");
This example shows a styled button:
Button button = new Button("Press Me"); CascadingStylesheet stylesheet = new CascadingStylesheet(); desktop.setStylesheet(stylesheet); EditableStyle buttonStyle = stylesheet.getSelectorStyle(new TypeSelector(Button.class)); buttonStyle.setBackground(new RectangularBackground(Colors.SILVER)); buttonStyle.setBorder(new RectangularBorder(Colors.BLACK, 1)); buttonStyle.setFont(Font.getFont("/fonts/source_sans_pro_24.ejf"));
This example shows a styled button with its background color changing on a press action:
Button button = new Button("Press Me"); CascadingStylesheet stylesheet = new CascadingStylesheet(); desktop.setStylesheet(stylesheet); EditableStyle buttonStyle = stylesheet.getSelectorStyle(new TypeSelector(Button.class)); buttonStyle.setBackground(new RectangularBackground(Colors.SILVER)); buttonStyle.setBorder(new RectangularBorder(Colors.BLACK, 1)); buttonStyle.setFont(Font.getFont("/fonts/source_sans_pro_24.ejf")); EditableStyle pressedButtonStyle = stylesheet .getSelectorStyle(new AndCombinator(new TypeSelector(Button.class), new StateSelector(States.ACTIVE))); pressedButtonStyle.setBackground(new RectangularBackground(Colors.GRAY));
Modifier and Type | Field and Description |
---|---|
static int |
ACTIVE
Active state.
|
Constructor and Description |
---|
Button()
Creates a button with an empty text.
|
Button(java.lang.String text)
Creates a button with the given text to display.
|
Modifier and Type | Method and Description |
---|---|
void |
handleClick()
Handles a click event.
|
boolean |
handleEvent(int event) |
boolean |
isInState(int state) |
void |
setOnClickListener(OnClickListener listener)
Sets the listener on the click events of this button.
|
computeContentOptimalSize, getText, renderContent, setText
addClassSelector, contains, containsWidget, getAbsoluteX, getAbsoluteY, getContentBounds, getDesktop, getHeight, getParent, getStyle, getWidgetAt, getWidth, getX, getY, hasClassSelector, isAttached, isEnabled, isShown, isTransparent, onAttached, onDetached, onHidden, onLaidOut, onShown, removeAllClassSelectors, removeClassSelector, render, requestLayOut, requestRender, requestRender, setClassSelectors, setEnabled, setPosition, setStyle, updateStyle
public static final int ACTIVE
public Button()
public Button(java.lang.String text)
text
- the text to display.public void setOnClickListener(@Nullable OnClickListener listener)
listener
- the listener to set.public boolean isInState(int state)
isInState
in class ej.mwt.Widget
public boolean handleEvent(int event)
handleEvent
in class ej.mwt.Widget
public void handleClick()