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(States.ACTIVE))); pressedButtonStyle.setBackground(new RectangularBackground(Colors.GRAY));
- Since:
- 2.3.0
-
-
Field Summary
Fields Modifier and Type Field Description static int
ACTIVE
Active state.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
handleClick()
Deprecated.Internal API.boolean
handleEvent(int event)
boolean
isInState(int state)
void
setOnClickListener(OnClickListener listener)
Sets the listener on the click events of this button.void
setPressed(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
public static final int ACTIVE
Active 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:
isInState
in classej.mwt.Widget
-
handleEvent
public boolean handleEvent(int event)
- Overrides:
handleEvent
in classej.mwt.Widget
-
setPressed
public void setPressed(boolean pressed)
Description copied from interface:Clickable
Changes the clickable element state.- Specified by:
setPressed
in interfaceClickable
- Parameters:
pressed
-true
if the element is pressed,false
otherwise.
-
handleClick
@Deprecated public void handleClick()
Deprecated.Internal API.Handles a click event.
-
-