org.gnu.gtk

Class Button

Known Direct Subclasses:
ColorButton, FontButton, OptionMenu, ToggleButton

public class Button
extends Bin

A widget that creates a signal when clicked on. This is generally used to attach a function to that is called when the button is pressed.

The gtk.Button widget can hold any valid child widget. That is it can hold most any other standard gtk.Widget. The most commonly used child is the gtk.Label.

Field Summary

Fields inherited from class org.gnu.glib.GObject

eventsInitialized

Constructor Summary

Button()
Creates a new Button widget
Button(String stockItem)
Constructs a button using a String that represents a stock item.
Button(String label, boolean hasMnemonic)
Creates a button widget with a gtk.Label child containing the given text.
Button(Handle handle)
Construct a button using a handle to a native resource.
Button(GtkStockItem stockItem)
Constructs a button using a stock item.

Method Summary

void
addListener(ButtonListener listener)
Register an object to handle button events.
void
click()
Sends a clicked signal to the button.
void
enter()
Sends an enter signal to the button.
protected void
fireButtonEvent(ButtonEvent event)
Class
getEventListenerClass(String signal)
EventType
getEventType(String signal)
boolean
getFocusOnClick()
Widget
getImage()
String
getLabel()
Returns the label which is being used on the button.
ReliefStyle
getRelief()
Returns the current relief style of the button
static Type
getType()
Retrieve the runtime type used by the GLib library.
boolean
getUseStock()
Returns true if this button is using stock items
boolean
getUseUnderline()
Returns whether an embedded underline in the button label indicates a mnemonic.
double
getXAlignment()
double
getYAlignment()
protected static void
gtk_button_clicked(Handle button)
protected static void
gtk_button_enter(Handle button)
protected static void
gtk_button_get_alignment(Handle button, double[] xalign, double[] yalign)
protected static boolean
gtk_button_get_focus_on_click(Handle button)
protected static Handle
gtk_button_get_image(Handle button)
protected static String
gtk_button_get_label(Handle button)
protected static int
gtk_button_get_relief(Handle button)
protected static int
gtk_button_get_type()
protected static boolean
gtk_button_get_use_stock(Handle button)
protected static boolean
gtk_button_get_use_underline(Handle button)
protected static void
gtk_button_leave(Handle button)
protected static Handle
gtk_button_new()
protected static Handle
gtk_button_new_from_stock(String stock_id)
protected static Handle
gtk_button_new_with_label(String label)
protected static Handle
gtk_button_new_with_mnemonic(String label)
protected static void
gtk_button_pressed(Handle button)
protected static void
gtk_button_released(Handle button)
protected static void
gtk_button_set_alignment(Handle button, double xalign, double yalign)
protected static void
gtk_button_set_focus_on_click(Handle button, boolean focus)
protected static void
gtk_button_set_image(Handle button, Handle image)
protected static void
gtk_button_set_label(Handle button, String label)
protected static void
gtk_button_set_relief(Handle button, int relief)
protected static void
gtk_button_set_use_stock(Handle button, boolean useStock)
protected static void
gtk_button_set_use_underline(Handle button, boolean useUnderline)
void
leave()
Sends a leave signal to the button.
void
press()
Sends a pressed signal to the button.
void
release()
Sends a released signal to the button.
void
removeListener(ButtonListener listener)
Removes a listener
void
setAlignment(double xalign, double yalign)
void
setFocusOnClick(boolean focusOnClick)
void
setImage(Widget image)
void
setLabel(String newLabel)
Sets the text of the label of the button to newLabel.
void
setRelief(ReliefStyle newRelief)
Sets the relief style of the edges of the Button widget.
void
setUseStock(boolean useStock)
Setting this will true will make the widget try to interpret the label as a stock item.
void
setUseUnderline(boolean useUnderLine)
If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.

Methods inherited from class org.gnu.gtk.Bin

getChild, getType, gtk_bin_get_child, gtk_bin_get_type

Methods inherited from class org.gnu.gtk.Container

add, addListener, fireContainerEvent, getBorderWidth, getChildren, getEventListenerClass, getEventType, getResizeMode, getType, gtk_container_add, gtk_container_check_resize, gtk_container_child_type, gtk_container_get_border_width, gtk_container_get_children, gtk_container_get_focus_chain, gtk_container_get_focus_hadjustment, gtk_container_get_focus_vadjustment, gtk_container_get_resize_mode, gtk_container_get_type, gtk_container_propagate_expose, gtk_container_remove, gtk_container_resize_children, gtk_container_set_border_width, gtk_container_set_focus_chain, gtk_container_set_focus_child, gtk_container_set_focus_hadjustment, gtk_container_set_focus_vadjustment, gtk_container_set_reallocate_redraws, gtk_container_set_resize_mode, gtk_container_unset_focus_chain, remove, removeListener, resizeChildren, setBorderWidth, setResizeMode

Methods inherited from class org.gnu.gtk.Widget

activate, addListener, addListener, addListener, addListener, addListener, addListener, addListener, addListener, canActivateAccel, createContext, createLayout, destroy, draw, drawArea, drawArea, findListener, finish, fireBooleanLifeCycleEvent, fireDragDestinationEvent, fireDragSourceEvent, fireExposeEvent, fireFocusEvent, fireKeyEvent, fireLifeCycleEvent, fireMouseEvent, fireMouseMotionEvent, getAccessible, getColormap, getContext, getData, getDisplay, getEventListenerClass, getEventType, getModifierStyle, getName, getParent, getParentWindow, getPointer, getRootWindow, getScreen, getSensitive, getStyle, getToplevel, getType, getWindow, grabDefault, grabFocus, gtk_drag_dest_set, gtk_drag_dest_unset, gtk_drag_finish, gtk_drag_get_data, gtk_drag_highlight, gtk_drag_source_set, gtk_drag_source_set_icon, gtk_drag_source_set_icon_pixbuf, gtk_drag_source_set_icon_stock, gtk_drag_source_unset, gtk_drag_unhighlight, gtk_widget_activate, gtk_widget_add_accelerator, gtk_widget_add_events, gtk_widget_add_mnemonic_label, gtk_widget_can_activate_accel, gtk_widget_child_focus, gtk_widget_child_notify, gtk_widget_class_path, gtk_widget_create_pango_context, gtk_widget_create_pango_layout, gtk_widget_destroy, gtk_widget_destroyed, gtk_widget_ensure_style, gtk_widget_event, gtk_widget_freeze_child_notify, gtk_widget_get_accessible, gtk_widget_get_ancestor, gtk_widget_get_child_requisition, gtk_widget_get_child_visible, gtk_widget_get_colormap, gtk_widget_get_composite_name, gtk_widget_get_default_colormap, gtk_widget_get_default_direction, gtk_widget_get_default_style, gtk_widget_get_default_visual, gtk_widget_get_direction, gtk_widget_get_display, gtk_widget_get_events, gtk_widget_get_extension_events, gtk_widget_get_modifier_style, gtk_widget_get_name, gtk_widget_get_pango_context, gtk_widget_get_parent, gtk_widget_get_parent_window, gtk_widget_get_pointer, gtk_widget_get_root_window, gtk_widget_get_screen, gtk_widget_get_sensitive, gtk_widget_get_settings, gtk_widget_get_size_request, gtk_widget_get_style, gtk_widget_get_toplevel, gtk_widget_get_type, gtk_widget_get_visual, gtk_widget_get_window, gtk_widget_grab_default, gtk_widget_grab_focus, gtk_widget_has_screen, gtk_widget_hide, gtk_widget_hide_all, gtk_widget_hide_on_delete, gtk_widget_intersect, gtk_widget_is_ancestor, gtk_widget_is_focus, gtk_widget_list_accel_closures, gtk_widget_list_mnemonic_labels, gtk_widget_map, gtk_widget_mnemonic_activate, gtk_widget_modify_base, gtk_widget_modify_bg, gtk_widget_modify_fg, gtk_widget_modify_font, gtk_widget_modify_style, gtk_widget_modify_text, gtk_widget_path, gtk_widget_pop_colormap, gtk_widget_pop_composite_child, gtk_widget_push_colormap, gtk_widget_push_composite_child, gtk_widget_queue_draw, gtk_widget_queue_draw_area, gtk_widget_queue_resize, gtk_widget_realize, gtk_widget_ref, gtk_widget_region_intersect, gtk_widget_remove_accelerator, gtk_widget_remove_mnemonic_label, gtk_widget_render_icon, gtk_widget_reparent, gtk_widget_reset_rc_styles, gtk_widget_send_expose, gtk_widget_set_accel_path, gtk_widget_set_app_paintable, gtk_widget_set_child_visible, gtk_widget_set_colormap, gtk_widget_set_composite_name, gtk_widget_set_default_colormap, gtk_widget_set_default_direction, gtk_widget_set_direction, gtk_widget_set_double_buffered, gtk_widget_set_events, gtk_widget_set_extension_events, gtk_widget_set_name, gtk_widget_set_parent, gtk_widget_set_parent_window, gtk_widget_set_redraw_on_allocate, gtk_widget_set_scroll_adjustments, gtk_widget_set_sensitive, gtk_widget_set_size_request, gtk_widget_set_state, gtk_widget_set_style, gtk_widget_shape_combine_mask, gtk_widget_show, gtk_widget_show_all, gtk_widget_show_now, gtk_widget_size_allocate, gtk_widget_size_request, gtk_widget_style_get_property, gtk_widget_thaw_child_notify, gtk_widget_translate_coordinates, gtk_widget_unmap, gtk_widget_unparent, gtk_widget_unrealize, gtk_widget_unref, handleButtonPressed, handleButtonReleased, handleDelete, handleDragDataGet, handleDragDestination, handleExpose, handleFocusIn, handleFocusOut, handleHide, handleKeyPressed, handleKeyReleased, handleMap, handleMouseEnter, handleMouseLeave, handleMouseMotion, handleNoExpose, handleRealize, handleScroll, handleShow, handleUnmap, hasFocus, hasScreen, hide, hideAll, highlight, intersect, isAncestor, makeWidget, modifyStyle, popColormap, pushColormap, realize, removeListener, removeListener, removeListener, removeListener, removeListener, removeListener, removeListener, removeListener, reparent, setBackgroundColor, setBaseColor, setColormap, setDoubleBuffered, setDragDestination, setDragIcon, setDragIconPixbuf, setDragIconStock, setDragSource, setFont, setForegroundColor, setMinimumSize, setName, setNoDragDestination, setNoDragSource, setSensitive, setTextColor, shapeCombineMask, show, showAll, unHighlight

Methods inherited from class org.gnu.gtk.GtkObject

destroy, getFlags, getType, gtk_object_destroy, gtk_object_get_type, gtk_object_sink, setFlags, sink

Methods inherited from class org.gnu.glib.GObject

addEventHandler, addEventHandler, addEventHandler, addEventHandler, addEventHandler, addEventHandler, addListener, equals, freezeNotify, getBooleanProperty, getData, getData, getDoubleProperty, getEventListenerClass, getEventType, getFloatProperty, getGObjectFromHandle, getHandle, getIntFromHandle, getIntProperty, getJavaObjectProperty, getLongProperty, getNullHandle, getPixbufProperty, getProperty, getStringFromHandle, getStringProperty, hasProperty, hashCode, instantiateJGObjectFromGType, notify, removeEventHandler, removeListener, retrieveGObject, setBooleanProperty, setData, setData, setDoubleProperty, setFloatProperty, setHandle, setIntProperty, setJavaObjectProperty, setLongProperty, setPixbufProperty, setProperty, setStringProperty, thawNotify

Constructor Details

Button

public Button()
Creates a new Button widget


Button

public Button(String stockItem)
Constructs a button using a String that represents a stock item. Stock items are standard icons and text strings. The use of these is highly encouraged as they allow gtk themes to have greater control over applications and so give a more consistant interface to the user.
Example: Button myButton = new Button( StockItem.NO; )

Parameters:
stockItem - A String representing a stock item

See Also:
GtkStockItem


Button

public Button(String label,
              boolean hasMnemonic)
Creates a button widget with a gtk.Label child containing the given text.

If hasMnemonic is true, the label will be interpreted as containing Mnemonic characters (keyboard accelerators). If characters in label are proceeded by an underscore character, they will be underlined. The first underlined character will be taken as the mnemonic - pressing Alt and that character will activate the button.

Parameters:
label - Text to appear on the button
hasMnemonic - See above description


Button

public Button(Handle handle)
Construct a button using a handle to a native resource.


Button

public Button(GtkStockItem stockItem)
Constructs a button using a stock item. Stock items are standard icons and text strings. The use of these is highly encouraged as they allow gtk themes to have greater control over applications and so give a more consistant interface to the user.
Example: Button myButton = new Button( new StockItem( StockItem.NO ); )

Parameters:
stockItem - A gtk stock item

See Also:
GtkStockItem

Method Details

addListener

public void addListener(ButtonListener listener)
Register an object to handle button events.

See Also:
ButtonListener


click

public void click()
Sends a clicked signal to the button. If handlers have been set up for this event, they will be called


enter

public void enter()
Sends an enter signal to the button. If handlers have been set up for this event, they will be called.


fireButtonEvent

protected void fireButtonEvent(ButtonEvent event)


getEventListenerClass

public Class getEventListenerClass(String signal)
Overrides:
getEventListenerClass in interface Container


getEventType

public EventType getEventType(String signal)
Overrides:
getEventType in interface Container


getFocusOnClick

public boolean getFocusOnClick()


getImage

public Widget getImage()


getLabel

public String getLabel()
Returns the label which is being used on the button.


getRelief

public ReliefStyle getRelief()
Returns the current relief style of the button


getType

public static Type getType()
Retrieve the runtime type used by the GLib library.
Overrides:
getType in interface Bin


getUseStock

public boolean getUseStock()
Returns true if this button is using stock items


getUseUnderline

public boolean getUseUnderline()
Returns whether an embedded underline in the button label indicates a mnemonic.


getXAlignment

public double getXAlignment()


getYAlignment

public double getYAlignment()


gtk_button_clicked

protected static final void gtk_button_clicked(Handle button)


gtk_button_enter

protected static final void gtk_button_enter(Handle button)


gtk_button_get_alignment

protected static final void gtk_button_get_alignment(Handle button,
                                                     double[] xalign,
                                                     double[] yalign)


gtk_button_get_focus_on_click

protected static final boolean gtk_button_get_focus_on_click(Handle button)


gtk_button_get_image

protected static final Handle gtk_button_get_image(Handle button)


gtk_button_get_label

protected static final String gtk_button_get_label(Handle button)


gtk_button_get_relief

protected static final int gtk_button_get_relief(Handle button)


gtk_button_get_type

protected static final int gtk_button_get_type()


gtk_button_get_use_stock

protected static final boolean gtk_button_get_use_stock(Handle button)


gtk_button_get_use_underline

protected static final boolean gtk_button_get_use_underline(Handle button)


gtk_button_leave

protected static final void gtk_button_leave(Handle button)


gtk_button_new

protected static final Handle gtk_button_new()


gtk_button_new_from_stock

protected static final Handle gtk_button_new_from_stock(String stock_id)


gtk_button_new_with_label

protected static final Handle gtk_button_new_with_label(String label)


gtk_button_new_with_mnemonic

protected static final Handle gtk_button_new_with_mnemonic(String label)


gtk_button_pressed

protected static final void gtk_button_pressed(Handle button)


gtk_button_released

protected static final void gtk_button_released(Handle button)


gtk_button_set_alignment

protected static final void gtk_button_set_alignment(Handle button,
                                                     double xalign,
                                                     double yalign)


gtk_button_set_focus_on_click

protected static final void gtk_button_set_focus_on_click(Handle button,
                                                          boolean focus)


gtk_button_set_image

protected static final void gtk_button_set_image(Handle button,
                                                 Handle image)


gtk_button_set_label

protected static final void gtk_button_set_label(Handle button,
                                                 String label)


gtk_button_set_relief

protected static final void gtk_button_set_relief(Handle button,
                                                  int relief)


gtk_button_set_use_stock

protected static final void gtk_button_set_use_stock(Handle button,
                                                     boolean useStock)


gtk_button_set_use_underline

protected static final void gtk_button_set_use_underline(Handle button,
                                                         boolean useUnderline)


leave

public void leave()
Sends a leave signal to the button. If handlers have been set up for this event, they will be called.


press

public void press()
Sends a pressed signal to the button. If handlers have been set up for this event then they will be called


release

public void release()
Sends a released signal to the button. If handlers have been set up for this event, they will be called.


removeListener

public void removeListener(ButtonListener listener)
Removes a listener

See Also:
addListener(ButtonListener)


setAlignment

public void setAlignment(double xalign,
                         double yalign)


setFocusOnClick

public void setFocusOnClick(boolean focusOnClick)


setImage

public void setImage(Widget image)


setLabel

public void setLabel(String newLabel)
Sets the text of the label of the button to newLabel. If setUseStock has been called or this object was created using stock buttons, then newLabel should be the name of the stock item to be used.


setRelief

public void setRelief(ReliefStyle newRelief)
Sets the relief style of the edges of the Button widget.


setUseStock

public void setUseStock(boolean useStock)
Setting this will true will make the widget try to interpret the label as a stock item. If the stock id is unknown, it will be treated as a normal label.

Stock items are standard icons and strings. These are included in Gtk themes, so that the appearance of all applications follows their theme. The use of stock items is highly recommended.

Parameters:
useStock - true if this button should use stock items


setUseUnderline

public void setUseUnderline(boolean useUnderLine)
If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.