Package ej.widget.basic
Class Button
- java.lang.Object
-
- ej.mwt.Widget
-
- ej.widget.basic.Label
-
- ej.widget.basic.Button
-
- All Implemented Interfaces:
Clickable
public class Button extends Label implements Clickable
A button is a widget that displays a text and reacts to click events.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(StateSelector.ACTIVE))); pressedButtonStyle.setBackground(new RectangularBackground(Colors.GRAY));
- Since:
- 2.3.0
-
-
Field Summary
Fields Modifier and Type Field Description static intACTIVEDeprecated.StateSelector.ACTIVEis better suited
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidhandleClick()Deprecated.Internal API.booleanhandleEvent(int event)booleanisInState(int state)voidsetOnClickListener(OnClickListener listener)Sets the listener on the click events of this button.voidsetPressed(boolean pressed)Changes the clickable element state.-
Methods inherited from class ej.widget.basic.Label
computeContentOptimalSize, getText, renderContent, setText
-
Methods inherited from class ej.mwt.Widget
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
-
-
-
-
Field Detail
-
ACTIVE
@Deprecated public static final int ACTIVE
Deprecated.StateSelector.ACTIVEis better suitedActive state.- See Also:
- Constant Field Values
-
-
Method Detail
-
setOnClickListener
public void setOnClickListener(@Nullable OnClickListener listener)Sets the listener on the click events of this button.- Parameters:
listener- the listener to set.
-
isInState
public boolean isInState(int state)
- Overrides:
isInStatein classej.mwt.Widget
-
handleEvent
public boolean handleEvent(int event)
- Overrides:
handleEventin classej.mwt.Widget
-
setPressed
public void setPressed(boolean pressed)
Description copied from interface:ClickableChanges the clickable element state.- Specified by:
setPressedin interfaceClickable- Parameters:
pressed-trueif the element is pressed,falseotherwise.
-
handleClick
@Deprecated public void handleClick()
Deprecated.Internal API.Handles a click event.
-
-