public class Button extends Bin implements Activatable
Button(String)
constructor.
Since Button is a Bin it strictly only has one child. Internally, however,
it may have both an icon image and some text (which is the look commonly
seen in the action buttons in Dialog boxes). You can add such an image to a
Button by calling setImage()
; this works alongside
and with setLabel()
. The machinery within Button
will manage creating the necessary internal structure (HBoxes, Alignments,
etc).
Modifier and Type | Class and Description |
---|---|
static interface |
Button.Clicked
Event generated when a user presses and releases a button, causing it
to activate.
|
Widget.ButtonPressEvent, Widget.ButtonReleaseEvent, Widget.Destroy, Widget.Draw, Widget.EnterNotifyEvent, Widget.FocusInEvent, Widget.FocusOutEvent, Widget.Hide, Widget.KeyPressEvent, Widget.KeyReleaseEvent, Widget.LeaveNotifyEvent, Widget.MapEvent, Widget.MotionNotifyEvent, Widget.PopupMenu, Widget.QueryTooltip, Widget.ScrollEvent, Widget.SizeAllocate, Widget.UnmapEvent, Widget.VisibilityNotifyEvent
Constructor and Description |
---|
Button()
Create an "empty" button to use as a Container.
|
Button(Stock stock)
Create a new Button with a Label and Image from a StockItem.
|
Button(String text)
Create a button with a Label as its child.
|
Modifier and Type | Method and Description |
---|---|
void |
connect(Button.Clicked handler)
Hook up a handler to receive
Button.Clicked events on this
Button. |
void |
emitClicked()
Cause a
Button.Clicked signal to be emitted. |
float |
getAlignmentX()
Get the horizontal alignment of the child Widget within this Button.
|
float |
getAlignmentY()
Get the vertical alignment of the child Widget within this Button.
|
Image |
getImage()
Get the Image associated with this Button.
|
String |
getLabel()
Get the text showing on the Button.
|
Action |
getRelatedAction()
Get the Action that is triggered when this Activatable is activated, if
any.
|
ReliefStyle |
getRelief()
Get the relief style in use around this Button.
|
void |
setAlignment(float xalign,
float yalign)
Set the alignment of the child Widget within the Button.
|
void |
setFocusOnClick(boolean setting)
Set whether clicking the Button will cause the Button to grab the
focus.
|
void |
setImage(Image image)
Paint an arbitrary Image over this Button.
|
void |
setLabel(String text)
Set the text showing in the Button.
|
void |
setRelatedAction(Action action)
Set the Action that is triggered when this Activatable is activated.
|
void |
setRelief(ReliefStyle style)
Set the "relief" style used to determine how the edges of this Button
will be decorated.
|
add, getChildren, remove, setBorderWidth
activate, addEvents, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, connect, destroy, getAllocatedHeight, getAllocatedWidth, getAllocation, getCanDefault, getCanFocus, getHasFocus, getName, getParent, getPreferredHeightForWidthMinimum, getPreferredHeightForWidthNatural, getPreferredHeightMinimum, getPreferredHeightNatural, getPreferredWidthForHeightMinimum, getPreferredWidthForHeightNatural, getPreferredWidthMinimum, getPreferredWidthNatural, getRequestMode, getRequisition, getSensitive, getStyleContext, getToplevel, getWindow, grabAdd, grabDefault, grabFocus, grabRemove, hide, isSensitive, overrideBackground, overrideColor, overrideFont, queueDraw, queueDrawArea, realize, setAlignHorizontal, setAlignVertical, setCanDefault, setCanFocus, setEvents, setExpandHorizontal, setExpandVertical, setName, setSensitive, setSizeRequest, setTooltipMarkup, setTooltipText, show, showAll
public Button()
add()
the Widget which will
be the Button's child.
For most uses setImage()
and
setLabel()
will more than take care of
things; they can be used together.
public Button(Stock stock)
stock
- The stock item that will determine the text and icon of the
Button.public Button(String text)
Note that you can use setImage()
on a
Button created this way.
text
- the text you wish on the Label that will be created in the
Button.public void connect(Button.Clicked handler)
Button.Clicked
events on this
Button. See Button.Clicked
for a detailed discussion of how to
connect signals.public void emitClicked()
Button.Clicked
signal to be emitted.public float getAlignmentX()
public float getAlignmentY()
public Image getImage()
setImage()
method, or
null
if the Button doesn't have one set.public String getLabel()
null
if the no-arg
constructor was used and you've just got an arbitrary
Widget-containing-Button, not the more usual Button-with-Label.public Action getRelatedAction()
Activatable
getRelatedAction
in interface Activatable
public ReliefStyle getRelief()
public void setAlignment(float xalign, float yalign)
xalign
- from 0.0f representing fully left-aligned through 1.0f
representing fully right-aligned.yalign
- from 0.0f for fully top-aligned through 1.0f for fully
bottom-alignedpublic void setFocusOnClick(boolean setting)
true
, the behaviour you're
accustomed to with regular Buttons. Setting this to false
is only used in unusual situations like toolboxes where you don't want
to steal focus away from where the main action is taking place.public void setImage(Image image)
setLabel()
in which case you will get an
icon on the left and the label text on the right.public void setLabel(String text)
If you created an empty Button without a Label using Button()
, this will create a Label nested in an Alignment for you.
That won't work if you create an empty Button then put a custom
Widget in place with add()
instead of
employing this method and/or setImage()
).
public void setRelatedAction(Action action)
Activatable
This replaced Action's connectProxy().
setRelatedAction
in interface Activatable
public void setRelief(ReliefStyle style)
NORMAL
which results in a Button just as you would expect, screaming out to be
pressed! There are two other variations, see ReliefStyle
for
details.