org.gnome.gtk

Class Button


public class Button
extends Bin

A Widget that creates a signal when clicked on. Button can hold any just about any other Widget as its child (TODO which means what? What limitations?). The most commonly used child is a Label, and there are convenience methods to help you just create a button with a given label automatically.
Author:
Andrew Cowie
Since:
4.0.0

Nested Class Summary

static interface
Button.CLICKED
Event generated when a user presses and releases a button, causing it to activate.

Nested classes/interfaces inherited from class org.gnome.gtk.Widget

Widget.ENTER_NOTIFY_EVENT, Widget.FOCUS_OUT_EVENT

Constructor Summary

Button()
Create an "empty" button to use as a Container.
Button(String text)
Create a button with a Label as its child.

Method Summary

void
connect(Button.CLICKED handler)
Hook up a handler to receive "clicked" events on this Button.
float
getAlignmentX()
String
getLabel()
Get the text showing on the Button.
ReliefStyle
getRelief()
Get the relief style in use around this Button.
void
setLabel(String text)
Set the text showing in the Button.
void
setRelief(ReliefStyle style)
Set the "relief" style used to determine how the edges of this Button will be decorated.

Methods inherited from class org.gnome.gtk.Bin

getChild

Methods inherited from class org.gnome.gtk.Container

add, remove

Methods inherited from class org.gnome.gtk.Widget

connect, connect, getParent, show, showAll

Methods inherited from class org.freedesktop.bindings.Proxy

toString

Constructor Details

Button

public Button()
Create an "empty" button to use as a Container. You'll need to add() the Widget which will be the Button's child.
Since:
4.0.0

Button

public Button(String text)
Create a button with a Label as its child. Simply specify the text you want for the Label and a Button will be created accordingly. This is quite a common case - in fact, we're generally more used to thinking of Buttons as being Labels that you can press than as arbitrary Widget Containers.
Parameters:
text - the text you wish on the Label that will be created in the Button.
Since:
4.0.0

Method Details

connect

public void connect(Button.CLICKED handler)
Hook up a handler to receive "clicked" events on this Button. A typical example of how this is used is as follows:
 Button b;
   
 b.connect(new Button.CLICKED() {
     public void onClicked(Button source) {
         // do something!
     }
 }
 

You can of course create a subclass of Button.CLICKED and then use instances of it if you have highly complicated algorithms to implement.

If you implement Button.CLICKED in the class you're currently working on, then you use a technique called "self-delegation" which can sometimes work well;

 b.connect(this);
 

getAlignmentX

public float getAlignmentX()

getLabel

public String getLabel()
Get the text showing on the Button.
Returns:
the text of the Label, or 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.
Since:
4.0.0

getRelief

public ReliefStyle getRelief()
Get the relief style in use around this Button.
Since:
4.0.1

setLabel

public void setLabel(String text)
Since:
4.0.0

setRelief

public void setRelief(ReliefStyle style)
Set the "relief" style used to determine how the edges of this Button will be decorated. The default is 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.
Since:
4.0.1