public class Button extends Label
Modifier and Type | Field and Description |
---|---|
static int |
STATE_DEFAULT
Indicates the default state of a button which is neither pressed nor focused
|
static int |
STATE_PRESSED
Indicates the pressed state of a button
|
static int |
STATE_ROLLOVER
Indicates the rollover state of a button which is equivalent to focused for
most uses
|
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, LEFT, RIGHT, TOP
Constructor and Description |
---|
Button()
Constructs a button with an empty string for its text.
|
Button(Command cmd)
Allows binding a command to a button for ease of use
|
Button(Image icon)
Constructs a button with the specified image.
|
Button(String text)
Constructs a button with the specified text.
|
Button(String text,
Image icon)
Constructor a button with text and image
|
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(ActionListener l)
Adds a listener to the button which will cause an event to dispatch on click
|
boolean |
animate()
Allows the animation to reduce "repaint" calls when it returns false.
|
protected Dimension |
calcPreferredSize()
Calculates the preferred size based on component content.
|
protected void |
dragInitiated()
Invoked on the focus component to let it know that drag has started on the parent container
for the case of a component that doesn't support scrolling
|
protected void |
fireClicked()
When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method
in order to allow 3 button devices to work properly.
|
Vector |
getActionListeners()
Deprecated.
use getListeners instead
|
protected Border |
getBorder()
Normally returns getStyle().getBorder() but some subclasses might use this
to programmatically replace the border in runtime e.g.
|
Command |
getCommand()
This method return the Button Command if exists
|
Image |
getDisabledIcon()
Indicates the icon that is displayed on the button when the button is in
the disabled state
|
Image |
getIconFromState()
Returns the icon for the button based on its current state
|
Collection |
getListeners()
Returns a collection containing the action listeners for this button
|
Image |
getPressedIcon()
Indicates the icon that is displayed on the button when the button is in
pressed state
|
int |
getReleaseRadius()
Indicates a radius in which a pointer release will still have effect.
|
Image |
getRolloverIcon()
Indicates the icon that is displayed on the button when the button is in
rolled over state
|
Image |
getRolloverPressedIcon()
Indicates the icon that is displayed on the button when the button is in
pressed state and is selected.
|
int |
getState()
Returns the button state
|
boolean |
isOppositeSide()
Places the check box or radio button on the opposite side at the far end
|
protected boolean |
isSelectableInteraction()
This method allows a component to indicate that it is interested in an "implicit" select
command to appear in the "fire" button when 3 softbuttons are defined in a device.
|
boolean |
isSelected()
Returns true if the button is selected for toggle buttons,
|
boolean |
isToggle()
Toggle button mode is only relevant for checkboxes/radio buttons.
|
void |
keyPressed(int keyCode)
If this Component is focused, the key pressed event
will call this method
|
void |
keyReleased(int keyCode)
If this Component is focused, the key released event
will call this method
|
void |
keyRepeated(int keyCode)
If this Component is focused, the key repeat event
will call this method.
|
void |
paint(Graphics g)
This method paints the Component on the screen, it should be overriden
by subclasses to perform custom drawing or invoke the UI API's to let
the PLAF perform the rendering.
|
void |
pointerDragged(int x,
int y)
If this Component is focused, the pointer dragged event
will call this method
|
void |
pointerHover(int[] x,
int[] y)
Invoked for devices where the pointer can hover without actually clicking
the display.
|
void |
pointerHoverReleased(int[] x,
int[] y)
Invoked for devices where the pointer can hover without actually clicking
the display.
|
void |
pointerPressed(int x,
int y)
If this Component is focused, the pointer pressed event
will call this method
|
void |
pointerReleased(int x,
int y)
If this Component is focused, the pointer released event
will call this method
|
void |
pressed()
Invoked to change the state of the button to the pressed state
|
void |
released()
Invoked to change the state of the button to the released state
|
void |
released(int x,
int y)
Invoked to change the state of the button to the released state
|
void |
removeActionListener(ActionListener l)
Removes the given action listener from the button
|
protected void |
resetFocusable()
Restores the state of the focusable flag to its default state
|
void |
setAlignment(int align)
Deprecated.
use the Style alignment instead
|
void |
setCommand(Command cmd)
Applies the given command to this button
|
void |
setDisabledIcon(Image disabledIcon)
Indicates the icon that is displayed on the button when the button is in
the disabled state
|
void |
setPressedIcon(Image pressedIcon)
Indicates the icon that is displayed on the button when the button is in
pressed state
|
void |
setReleaseRadius(int releaseRadius)
Indicates a radius in which a pointer release will still have effect.
|
void |
setRolloverIcon(Image rolloverIcon)
Indicates the icon that is displayed on the button when the button is in
rolled over state
|
void |
setRolloverPressedIcon(Image rolloverPressedIcon)
Indicates the icon that is displayed on the button when the button is in
pressed state and is selected.
|
void |
setToggle(boolean toggle)
Toggle button mode is only relevant for checkboxes/radio buttons.
|
bindProperty, getAlignment, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBoundPropertyValue, getGap, getIcon, getMask, getMaskedIcon, getMaskName, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getShiftMillimeters, getShiftText, getText, getTextPosition, getVerticalAlignment, isDefaultTickerEnabled, isEndsWith3Points, isShouldLocalize, isTickerEnabled, isTickerRunning, paramString, setBoundPropertyValue, setDefaultTickerEnabled, setEndsWith3Points, setGap, setIcon, setMask, setMaskName, setPropertyValue, setShiftMillimeters, setShiftText, setShouldLocalize, setText, setTextPosition, setTickerEnabled, setVerticalAlignment, shouldTickerStart, startTicker, startTicker, stopTicker, unbindProperty
addDragOverListener, addDropListener, addFocusListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, calcScrollSize, cancelRepaints, clearClientProperties, contains, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, draggingOver, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getBottomGap, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getGridPosX, getGridPosY, getHeight, getLabelForComponent, getName, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getPressedStyle, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSideGap, getStyle, getTensileLength, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFocus, initComponent, initCustomStyle, initLaf, installDefaultPainter, isAlwaysTensile, isCellRenderer, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHideInPortrait, isInClippingRegion, isInitialized, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isVisible, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, paintBackground, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintLock, paintLockRelease, paintScrollbars, paintScrollbarX, paintScrollbarY, pinch, pointerDragged, pointerHoverPressed, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, removeDragOverListener, removeDropListener, removeFocusListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, repaint, repaint, requestFocus, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHideInPortrait, setInitialized, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setPressedStyle, setRTL, setSameHeight, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTactileTouch, setTensileDragEnabled, setTensileLength, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, styleChanged, toString
public static final int STATE_ROLLOVER
public static final int STATE_PRESSED
public static final int STATE_DEFAULT
public Button()
public Button(String text)
text
- label appearing on the buttonpublic Button(Command cmd)
cmd
- command whose text would be used for the button and would recive action events
from the buttonpublic Button(Image icon)
icon
- appearing on the buttonpublic void setCommand(Command cmd)
cmd
- the command on the buttonprotected void resetFocusable()
Component
resetFocusable
in class Component
public int getState()
public Image getPressedIcon()
STATE_PRESSED
public Image getRolloverPressedIcon()
public void setRolloverPressedIcon(Image rolloverPressedIcon)
rolloverPressedIcon
- icon usedpublic Image getDisabledIcon()
public Image getRolloverIcon()
STATE_ROLLOVER
public void setRolloverIcon(Image rolloverIcon)
rolloverIcon
- icon to useSTATE_ROLLOVER
public void setPressedIcon(Image pressedIcon)
pressedIcon
- icon usedSTATE_PRESSED
public void setDisabledIcon(Image disabledIcon)
disabledIcon
- icon usedpublic void addActionListener(ActionListener l)
l
- implementation of the action listener interfacepublic void removeActionListener(ActionListener l)
l
- implementation of the action listener interfacepublic Vector getActionListeners()
public Collection getListeners()
public Image getIconFromState()
public void pressed()
public void released()
public void released(int x, int y)
x
- the x position if a touch event triggered this, -1 if this isn't relevanty
- the y position if a touch event triggered this, -1 if this isn't relevantpublic void keyPressed(int keyCode)
Component
keyPressed
in class Component
keyCode
- the key code value to indicate a physical key.public void keyReleased(int keyCode)
Component
keyReleased
in class Component
keyCode
- the key code value to indicate a physical key.public void keyRepeated(int keyCode)
Component
keyRepeated
in class Component
keyCode
- the key code value to indicate a physical key.protected void fireClicked()
Component
fireClicked
in class Component
protected boolean isSelectableInteraction()
Component
isSelectableInteraction
in class Component
public void pointerHover(int[] x, int[] y)
Component
pointerHover
in class Component
x
- the pointer x coordinatey
- the pointer y coordinatepublic void pointerHoverReleased(int[] x, int[] y)
Component
pointerHoverReleased
in class Component
x
- the pointer x coordinatey
- the pointer y coordinatepublic void pointerPressed(int x, int y)
Component
pointerPressed
in class Component
x
- the pointer x coordinatey
- the pointer y coordinatepublic void pointerReleased(int x, int y)
Component
pointerReleased
in class Component
x
- the pointer x coordinatey
- the pointer y coordinateprotected void dragInitiated()
Component
dragInitiated
in class Component
public void pointerDragged(int x, int y)
Component
pointerDragged
in class Component
x
- the pointer x coordinatey
- the pointer y coordinatepublic void paint(Graphics g)
Component
protected Dimension calcPreferredSize()
Component
calcPreferredSize
in class Label
protected Border getBorder()
Component
public Command getCommand()
public boolean isSelected()
public void setAlignment(int align)
Label
setAlignment
in class Label
align
- alignment valueComponent.CENTER
,
Component.LEFT
,
Component.RIGHT
public boolean isToggle()
public void setToggle(boolean toggle)
toggle
- the toggle to setpublic boolean animate()
Animation
Display
class.public boolean isOppositeSide()
public int getReleaseRadius()
public void setReleaseRadius(int releaseRadius)
releaseRadius
- the releaseRadius to set