javax.swing.plaf.basic

Class BasicButtonUI

public class BasicButtonUI extends ButtonUI

A UI delegate for the {@link JButton} component.
Field Summary
protected intdefaultTextIconGap
A constant used to pad out elements in the button's layout and preferred size calculations.
protected intdefaultTextShiftOffset
A constant added to the defaultTextIconGap to adjust the text within this particular button.
Method Summary
protected voidclearTextShiftOffset()
Sets the text shift offset to zero.
protected BasicButtonListenercreateButtonListener(AbstractButton b)
Creates and returns a new instance of {@link BasicButtonListener}.
static ComponentUIcreateUI(JComponent c)
Factory method to create an instance of BasicButtonUI for a given {@link JComponent}, which should be an {@link AbstractButton}.
intgetDefaultTextIconGap(AbstractButton b)
Returns the default gap between the button's text and icon (in pixels).
DimensiongetMaximumSize(JComponent c)
Calculates the maximum size for the specified component.
DimensiongetMinimumSize(JComponent c)
Calculates the minimum size for the specified component.
DimensiongetPreferredSize(JComponent c)
Calculate the preferred size of this component, by delegating to {@link BasicGraphicsUtils#getPreferredButtonSize}.
protected StringgetPropertyPrefix()
Returns the prefix for the UI defaults property for this UI class.
protected intgetTextShiftOffset()
Returns the text shift offset.
protected voidinstallDefaults(AbstractButton b)
Installs the default settings.
protected voidinstallKeyboardActions(AbstractButton b)
protected voidinstallListeners(AbstractButton b)
Installs listeners for the button.
voidinstallUI(JComponent c)
Install the BasicButtonUI as the UI for a particular component.
voidpaint(Graphics g, JComponent c)
Paint the component, which is an {@link AbstractButton}, according to its current state.
protected voidpaintButtonPressed(Graphics g, AbstractButton b)
Paints the background area of an {@link AbstractButton} in the pressed state.
protected voidpaintFocus(Graphics g, AbstractButton b, Rectangle vr, Rectangle tr, Rectangle ir)
Paint any focus decoration this {@link JComponent} might have.
protected voidpaintIcon(Graphics g, JComponent c, Rectangle iconRect)
Paint the icon for this component.
protected voidpaintText(Graphics g, JComponent c, Rectangle textRect, String text)
Paints the "text" property of an {@link AbstractButton}.
protected voidpaintText(Graphics g, AbstractButton b, Rectangle textRect, String text)
Paints the "text" property of an {@link AbstractButton}.
protected voidsetTextShiftOffset()
Sets the text shift offset to the value in {@link #defaultTextShiftOffset}.
protected voiduninstallDefaults(AbstractButton b)
Removes the defaults added by {@link #installDefaults(AbstractButton)}.
protected voiduninstallKeyboardActions(AbstractButton b)
protected voiduninstallListeners(AbstractButton b)
Uninstalls listeners for the button.
voiduninstallUI(JComponent c)
Uninstalls the UI from the component.

Field Detail

defaultTextIconGap

protected int defaultTextIconGap
A constant used to pad out elements in the button's layout and preferred size calculations.

defaultTextShiftOffset

protected int defaultTextShiftOffset
A constant added to the defaultTextIconGap to adjust the text within this particular button.

Method Detail

clearTextShiftOffset

protected void clearTextShiftOffset()
Sets the text shift offset to zero.

See Also: setTextShiftOffset

createButtonListener

protected BasicButtonListener createButtonListener(AbstractButton b)
Creates and returns a new instance of {@link BasicButtonListener}. This method provides a hook to make it easy for subclasses to install a different listener.

Parameters: b the button.

Returns: A new listener.

createUI

public static ComponentUI createUI(JComponent c)
Factory method to create an instance of BasicButtonUI for a given {@link JComponent}, which should be an {@link AbstractButton}.

Parameters: c The component.

Returns: A new UI capable of drawing the component

getDefaultTextIconGap

public int getDefaultTextIconGap(AbstractButton b)
Returns the default gap between the button's text and icon (in pixels).

Parameters: b the button (ignored).

Returns: The gap.

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Calculates the maximum size for the specified component.

Parameters: c the component for which to compute the maximum size

Returns: the maximum size for the specified component

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Calculates the minimum size for the specified component.

Parameters: c the component for which to compute the minimum size

Returns: the minimum size for the specified component

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Calculate the preferred size of this component, by delegating to {@link BasicGraphicsUtils#getPreferredButtonSize}.

Parameters: c The component to measure

Returns: The preferred dimensions of the component

getPropertyPrefix

protected String getPropertyPrefix()
Returns the prefix for the UI defaults property for this UI class. This is 'Button' for this class.

Returns: the prefix for the UI defaults property

getTextShiftOffset

protected int getTextShiftOffset()
Returns the text shift offset.

Returns: The text shift offset.

See Also: clearTextShiftOffset setTextShiftOffset

installDefaults

protected void installDefaults(AbstractButton b)
Installs the default settings.

Parameters: b the button (null not permitted).

installKeyboardActions

protected void installKeyboardActions(AbstractButton b)

installListeners

protected void installListeners(AbstractButton b)
Installs listeners for the button.

Parameters: b the button (null not permitted).

installUI

public void installUI(JComponent c)
Install the BasicButtonUI as the UI for a particular component. This means registering all the UI's listeners with the component, and setting any properties of the button which are particular to this look and feel.

Parameters: c The component to install the UI into

paint

public void paint(Graphics g, JComponent c)
Paint the component, which is an {@link AbstractButton}, according to its current state.

Parameters: g The graphics context to paint with c The component to paint the state of

paintButtonPressed

protected void paintButtonPressed(Graphics g, AbstractButton b)
Paints the background area of an {@link AbstractButton} in the pressed state. This means filling the supplied area with a darker than normal background.

Parameters: g The graphics context to paint with b The button to paint the state of

paintFocus

protected void paintFocus(Graphics g, AbstractButton b, Rectangle vr, Rectangle tr, Rectangle ir)
Paint any focus decoration this {@link JComponent} might have. The component, which in this case will be an {@link AbstractButton}, should only have focus decoration painted if it has the focus, and its "focusPainted" property is true.

Parameters: g Graphics context to paint with b Button to paint the focus of vr Visible rectangle, the area in which to paint tr Text rectangle, contained in visible rectangle ir Icon rectangle, contained in visible rectangle

See Also: isFocusPainted JComponent

paintIcon

protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect)
Paint the icon for this component. Depending on the state of the component and the availability of the button's various icon properties, this might mean painting one of several different icons.

Parameters: g Graphics context to paint with c Component to paint the icon of iconRect Rectangle in which the icon should be painted

paintText

protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text)
Paints the "text" property of an {@link AbstractButton}.

Parameters: g The graphics context to paint with c The component to paint the state of textRect The area in which to paint the text text The text to paint

paintText

protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text)
Paints the "text" property of an {@link AbstractButton}.

Parameters: g The graphics context to paint with b The button to paint the state of textRect The area in which to paint the text text The text to paint

Since: 1.4

setTextShiftOffset

protected void setTextShiftOffset()
Sets the text shift offset to the value in {@link #defaultTextShiftOffset}.

See Also: clearTextShiftOffset

uninstallDefaults

protected void uninstallDefaults(AbstractButton b)
Removes the defaults added by {@link #installDefaults(AbstractButton)}.

Parameters: b the button (null not permitted).

uninstallKeyboardActions

protected void uninstallKeyboardActions(AbstractButton b)

uninstallListeners

protected void uninstallListeners(AbstractButton b)
Uninstalls listeners for the button.

Parameters: b the button (null not permitted).

uninstallUI

public void uninstallUI(JComponent c)
Uninstalls the UI from the component.

Parameters: c the component from which to uninstall the UI