Class FlatButton
- All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable
class FlatButton
extends org.eclipse.swt.widgets.Canvas
- Styles:
- UP, DOWN, LEFT, RIGHT, CENTER
- Events:
- Selection
Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description FlatButton(org.eclipse.swt.widgets.Composite parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. -
Method Summary
Modifier and Type Method Description void
addListener(int eventType, org.eclipse.swt.widgets.Listener listener)
void
addSelectionListener(org.eclipse.swt.events.SelectionListener listener)
Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in theSelectionListener
interface.org.eclipse.swt.graphics.Point
computeSize(int wHint, int hHint, boolean changed)
int
getAlignment()
Returns a value which describes the position of the text in the receiver.org.eclipse.swt.graphics.Color
getBackgroundColor()
Returns a value which describes the default background colororg.eclipse.swt.graphics.Image
getImage()
Returns the receiver's image if it has one, or null if it does not.org.eclipse.swt.graphics.Color
getMouseOverColor()
Returns a value which describes the color when the mouse is over the buttonorg.eclipse.swt.graphics.Color
getSelectedColor()
Returns a value which describes the color when the button is selectedorg.eclipse.swt.graphics.Color
getSelectedTextColor()
Returns a value which describes the color of the text when the button is selectedboolean
getSelection()
Returnstrue
if the receiver is selected, and false otherwise.java.lang.String
getText()
Returns the receiver's text.void
removeSelectionListener(org.eclipse.swt.events.SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when the control is selected by the user.void
setAlignment(int alignment)
Controls how text, images and arrows will be displayed in the receiver.void
setBackgroundColor(org.eclipse.swt.graphics.Color backgroundColor)
Sets the receiver's background color to the color specified by the argument.void
setImage(org.eclipse.swt.graphics.Image image)
Sets the receiver's image to the argument, which may benull
indicating that no image should be displayed.void
setMouseOverColor(org.eclipse.swt.graphics.Color mouseOverColor)
Sets the receiver's color when the mouse if over the button.void
setSelectedColor(org.eclipse.swt.graphics.Color selectedColor)
Sets the receiver's color when the button is selected.void
setSelectedTextColor(org.eclipse.swt.graphics.Color selectedTextColor)
Sets the receiver's text color when the button is selected.void
setSelection(boolean selected)
Sets the selection state of the receiver.void
setText(java.lang.String text)
Sets the receiver's text.Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, getIME, scroll, setCaret, setFont, setIME
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList, toString
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData
-
Constructor Details
-
FlatButton
public FlatButton(org.eclipse.swt.widgets.Composite parent, int style)Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.The style value is either one of the style constants defined in class
SWT
which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a composite control which will be the parent of the new instance (cannot be null)style
- the style of control to construct- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
org.eclipse.swt.SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
- See Also:
SWT.DOWN
,SWT.LEFT
,SWT.RIGHT
,SWT.CENTER
-
-
Method Details
-
addSelectionListener
public void addSelectionListener(org.eclipse.swt.events.SelectionListener listener)Adds the listener to the collection of listeners who will be notified when the control is selected by the user, by sending it one of the messages defined in theSelectionListener
interface.widgetSelected
is called when the control is selected by the user.widgetDefaultSelected
is not called.- Parameters:
listener
- the listener which should be notified- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
SelectionListener
,removeSelectionListener(org.eclipse.swt.events.SelectionListener)
,SelectionEvent
-
computeSize
public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)- Overrides:
computeSize
in classorg.eclipse.swt.widgets.Control
- See Also:
Control.computeSize(int, int, boolean)
-
getAlignment
public int getAlignment()Returns a value which describes the position of the text in the receiver. The value will be one ofLEFT
,RIGHT
orCENTER
.- Returns:
- the alignment
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getBackgroundColor
public org.eclipse.swt.graphics.Color getBackgroundColor()Returns a value which describes the default background color- Returns:
- the default background color
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getImage
public org.eclipse.swt.graphics.Image getImage()Returns the receiver's image if it has one, or null if it does not.- Returns:
- the receiver's image
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getMouseOverColor
public org.eclipse.swt.graphics.Color getMouseOverColor()Returns a value which describes the color when the mouse is over the button- Returns:
- the color when the mouse is over the button
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelectedColor
public org.eclipse.swt.graphics.Color getSelectedColor()Returns a value which describes the color when the button is selected- Returns:
- the color when the button is selected
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelectedTextColor
public org.eclipse.swt.graphics.Color getSelectedTextColor()Returns a value which describes the color of the text when the button is selected- Returns:
- the color of the text when the button is selected
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getSelection
public boolean getSelection()Returnstrue
if the receiver is selected, and false otherwise.- Returns:
- the selection state
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getText
public java.lang.String getText()Returns the receiver's text.- Returns:
- the receiver's text
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
removeSelectionListener
public void removeSelectionListener(org.eclipse.swt.events.SelectionListener listener)Removes the listener from the collection of listeners who will be notified when the control is selected by the user.- Parameters:
listener
- the listener which should no longer be notified- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the listener is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
SelectionListener
,addSelectionListener(org.eclipse.swt.events.SelectionListener)
-
setAlignment
public void setAlignment(int alignment)Controls how text, images and arrows will be displayed in the receiver. The argument should be one ofLEFT
,RIGHT
orCENTER
.- Parameters:
alignment
- the new alignment- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setBackgroundColor
public void setBackgroundColor(org.eclipse.swt.graphics.Color backgroundColor)Sets the receiver's background color to the color specified by the argument.- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setImage
public void setImage(org.eclipse.swt.graphics.Image image)Sets the receiver's image to the argument, which may benull
indicating that no image should be displayed.Note that a Button can display an image and text simultaneously on Windows (starting with XP), GTK+ and OSX. On other platforms, a Button that has an image and text set into it will display the image or text that was set most recently.
- Parameters:
image
- the image to display on the receiver (may benull
)- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the image has been disposed
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setMouseOverColor
public void setMouseOverColor(org.eclipse.swt.graphics.Color mouseOverColor)Sets the receiver's color when the mouse if over the button.- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setSelectedColor
public void setSelectedColor(org.eclipse.swt.graphics.Color selectedColor)Sets the receiver's color when the button is selected.- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setSelectedTextColor
public void setSelectedTextColor(org.eclipse.swt.graphics.Color selectedTextColor)Sets the receiver's text color when the button is selected.- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setSelection
public void setSelection(boolean selected)Sets the selection state of the receiver.- Parameters:
selected
- the new selection state- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setText
public void setText(java.lang.String text)Sets the receiver's text.- Parameters:
string
- the new text- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the text is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
addListener
public void addListener(int eventType, org.eclipse.swt.widgets.Listener listener)- Overrides:
addListener
in classorg.eclipse.swt.widgets.Widget
- See Also:
Widget.addListener(int, org.eclipse.swt.widgets.Listener)
-