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
|
BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, 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
|
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.
|
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 |
getIconFromState()
Returns the icon for the button based on its current state
|
Image |
getPressedIcon()
Indicates the icon that is displayed on the button when the button is in
pressed state
|
Style |
getPressedStyle()
Returns the Component Style for the pressed state allowing us to manipulate
the look of the component when it is pressed
|
Image |
getRolloverIcon()
Indicates the icon that is displayed on the button when the button is in
rolled over state
|
int |
getState()
Returns the button state
|
Style |
getStyle()
Returns the Component Style allowing us to manipulate the look of the
component
|
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,
throws an exception if this is not a toggle button
|
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 |
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
|
protected void |
refreshTheme(String id)
Makes sure the component is up to date with the given UIID
|
void |
removeActionListener(ActionListener l)
Removes the given action listener from the button
|
void |
setPressedIcon(Image pressedIcon)
Indicates the icon that is displayed on the button when the button is in
pressed state
|
void |
setPressedStyle(Style style)
Sets the Component Style for the pressed state allowing us to manipulate
the look of the component when it is pressed
|
void |
setRolloverIcon(Image rolloverIcon)
Indicates the icon that is displayed on the button when the button is in
rolled over state
|
animate, getAlignment, getBaselineResizeBehavior, getGap, getIcon, getShiftText, getText, getTextPosition, getVerticalAlignment, isEndsWith3Points, isTickerEnabled, isTickerRunning, paramString, setAlignment, setEndsWith3Points, setGap, setIcon, setShiftText, setText, setTextPosition, setTickerEnabled, setVerticalAlignment, shouldTickerStart, startTicker, stopTicker
addFocusListener, calcScrollSize, contains, deinitialize, deinitializeCustomStyle, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getBaseline, getBottomGap, getBounds, getClientProperty, getComponentForm, getDirtyRegion, getHeight, getLabelForComponent, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getScrollAnimationSpeed, getScrollDimension, getScrollX, getScrollY, getSelectCommandText, getSelectedStyle, getSideGap, getUIID, getUnselectedStyle, getVisibleBounds, getWidth, getX, getY, handlesInput, hasFocus, initComponent, initCustomStyle, isBorderPainted, isDragActivated, isEnabled, isFocusable, isFocusPainted, isInitialized, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSmoothScrolling, isTactileTouch, isTactileTouch, isTensileDragEnabled, isVisible, laidOut, longKeyPress, longPointerPress, paintBackground, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintScrollbars, paintScrollbarX, paintScrollbarY, pointerDragged, pointerDragged, pointerPressed, pointerReleased, putClientProperty, refreshTheme, removeFocusListener, repaint, repaint, requestFocus, scrollRectToVisible, scrollRectToVisible, setBorderPainted, setCellRenderer, setDirtyRegion, setEnabled, setFocus, setFocusable, setFocusPainted, setHandlesInput, setHeight, setInitialized, setIsScrollVisible, setLabelForComponent, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setRTL, setScrollAnimationSpeed, setScrollSize, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setStyle, setTactileTouch, setTensileDragEnabled, setUIID, setUnselectedStyle, setUnSelectedStyle, setVisible, setWidth, setX, setY, 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 int getState()
public Image getPressedIcon()
STATE_PRESSED
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 addActionListener(ActionListener l)
l
- implementation of the action listener interfacepublic void removeActionListener(ActionListener l)
l
- implementation of the action listener interfacepublic Image getIconFromState()
public 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 paint(Graphics g)
Component
protected Dimension calcPreferredSize()
Component
calcPreferredSize
in class Label
protected Border getBorder()
Component
public Style getPressedStyle()
public void setPressedStyle(Style style)
style
- the component Style objectprotected void refreshTheme(String id)
Component
refreshTheme
in class Component
id
- The Style Id to update the Component withpublic Style getStyle()
Component
public Command getCommand()
public boolean isSelected()