APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.basic

public Class BasicButtonUI

extends ButtonUI
Class Inheritance
Known Direct Subclasses
javax.swing.plaf.basic.BasicToggleButtonUI, javax.swing.plaf.metal.MetalButtonUI, javax.swing.plaf.synth.SynthButtonUI, com.sun.java.swing.plaf.motif.MotifButtonUI
Imports
java.awt.AWTKeyStroke, .Component, .Dimension, .FontMetrics, .Graphics, .Insets, .KeyboardFocusManager, .Rectangle, java.awt.event.ActionEvent, .KeyEvent, .KeyListener, .MouseMotionListener, java.util.Enumeration, .HashSet, .Set, javax.swing.AbstractAction, .AbstractButton, .ButtonGroup, .ButtonModel, .DefaultButtonModel, .Icon, .JComponent, .JRadioButton, .JToggleButton, .KeyStroke, .LookAndFeel, .SwingUtilities, .UIManager, javax.swing.plaf.ButtonUI, .ComponentUI, .UIResource, javax.swing.text.View, sun.swing.SwingUtilities2

BasicButton implementation
Author
Jeff Dinkins

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
BasicButtonUI.ButtonGroupInfo

ButtonGroupInfo, used to get related info in button group for given toggle button

private class
BasicButtonUI.KeyHandler

Togglebutton KeyListener

private class
private class

Field Summary

Modifier and TypeField and Description
protected int
defaultTextIconGap

The default gap between a text and an icon.

protected int
defaultTextShiftOffset

The default offset of a text.

private static Rectangle
private KeyListener
private static final String
private int
private static Rectangle
private static final ComponentUI
private static Rectangle

Constructor Summary

AccessConstructor and Description
public
BasicButtonUI()

Constructs a BasicButtonUI.

Method Summary

Modifier and TypeMethod and Description
protected void
clearTextShiftOffset()

Clears the offset of the text.

protected BasicButtonListener

Returns:

a new instance of BasicButtonListener
createButtonListener
(AbstractButton
an abstract button
b
)

Returns a new instance of BasicButtonListener.

private KeyListener
createKeyListener()

Creates the key listener to handle tab navigation in JToggleButton Group.

public static ComponentUI

Returns:

an instance of BasicButtonUI
createUI
(JComponent
a component
c
)

Hides javax.swing.plaf.ComponentUI.createUI.

Returns an instance of BasicButtonUI.

public int
getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.ComponentUI.getBaseline.

Returns the baseline.

public Component.BaselineResizeBehavior
getBaselineResizeBehavior(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getBaselineResizeBehavior.

Returns an enum indicating how the baseline of the component changes as the size changes.

private BasicButtonListener
getButtonListener(AbstractButton b)

Returns the ButtonListener for the passed in Button, or null if one could not be found.

public int

Returns:

the default gap between text and an icon
getDefaultTextIconGap
(AbstractButton
an abstract button
b
)

Returns the default gap between a text and an icon.

public Dimension
getMaximumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

Returns the specified component's maximum size appropriate for the look and feel.

public Dimension
getMinimumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

Returns the specified component's minimum size appropriate for the look and feel.

public Dimension
getPreferredSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

Returns the specified component's preferred size appropriate for the look and feel.

protected String

Returns:

the property prefix
getPropertyPrefix
()

Returns the property prefix.

protected int

Returns:

the offset of the text
getTextShiftOffset
()

Returns the offset of the text.

protected void
installDefaults(AbstractButton
an abstract button
b
)

Installs default properties.

protected void
installKeyboardActions(AbstractButton
an abstract button
b
)

Registers keyboard actions.

protected void
installListeners(AbstractButton
an abstract button
b
)

Registers listeners.

public void
installUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.installUI.

Configures the specified component appropriately for the look and feel.

private boolean
private String
layout(AbstractButton b, FontMetrics fm, int width, int height)

public void
paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.paint.

Paints the specified component appropriately for the look and feel.

protected void
paintButtonPressed(Graphics
an instance of Graphics
g
,
AbstractButton
an abstract button
b
)

Paints a pressed button.

protected void
paintFocus(Graphics
an instance of Graphics
g
,
AbstractButton
an abstract button
b
,
Rectangle
a bounding rectangle to render the button
viewRect
,
Rectangle
a bounding rectangle to render the text
textRect
,
Rectangle
a bounding rectangle to render the icon
iconRect
)

Paints a focused button.

protected void
paintIcon(Graphics
an instance of Graphics
g
,
JComponent
a component
c
,
Rectangle
a bounding rectangle to render the icon
iconRect
)

Paints an icon of the current button.

protected void
paintText(Graphics
an instance of Graphics
g
,
JComponent
a component
c
,
Rectangle
a bounding rectangle to render the text
textRect
,
String
a string to render
text
)

Method which renders the text of the current button.

protected void
paintText(Graphics
Graphics context
g
,
AbstractButton
Current button to render
b
,
Rectangle
Bounding rectangle to render the text
textRect
,
String
String to render
text
)

Method which renders the text of the current button.

private void
selectToggleButton(ActionEvent event, boolean next)

Select toggle button based on "Previous" or "Next" operation

protected void
setTextShiftOffset()

Sets the offset of the text.

protected void
uninstallDefaults(AbstractButton
an abstract button
b
)

Uninstalls default properties.

protected void
uninstallKeyboardActions(AbstractButton
an abstract button
b
)

Unregisters keyboard actions.

protected void
uninstallListeners(AbstractButton
an abstract button
b
)

Unregisters listeners.

public void
uninstallUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

Reverses configuration which was done on the specified component during installUI.

Field Detail

defaultTextIconGapback to summary
protected int defaultTextIconGap

The default gap between a text and an icon.

defaultTextShiftOffsetback to summary
protected int defaultTextShiftOffset

The default offset of a text.

iconRectback to summary
private static Rectangle iconRect
keyListenerback to summary
private KeyListener keyListener
propertyPrefixback to summary
private static final String propertyPrefix
shiftOffsetback to summary
private int shiftOffset
textRectback to summary
private static Rectangle textRect
UIback to summary
private static final ComponentUI UI
viewRectback to summary
private static Rectangle viewRect

Constructor Detail

BasicButtonUIback to summary
public BasicButtonUI()

Constructs a BasicButtonUI.

Method Detail

clearTextShiftOffsetback to summary
protected void clearTextShiftOffset()

Clears the offset of the text.

createButtonListenerback to summary
protected BasicButtonListener createButtonListener(AbstractButton b)

Returns a new instance of BasicButtonListener.

Parameters
b:AbstractButton

an abstract button

Returns:BasicButtonListener

a new instance of BasicButtonListener

createKeyListenerback to summary
private KeyListener createKeyListener()

Creates the key listener to handle tab navigation in JToggleButton Group.

createUIback to summary
public static ComponentUI createUI(JComponent c)

Hides javax.swing.plaf.ComponentUI.createUI.

Returns an instance of BasicButtonUI.

Parameters
c:JComponent

a component

Returns:ComponentUI

an instance of BasicButtonUI

getBaselineback to summary
public int getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.ComponentUI.getBaseline.

Returns the baseline.

Exceptions
NullPointerException:
if c is null
IllegalArgumentException:
if width or height is < 0
Since
1.6
See Also
javax.swing.JComponent#getBaseline(int, int)
getBaselineResizeBehaviorback to summary
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getBaselineResizeBehavior.

Returns an enum indicating how the baseline of the component changes as the size changes.

Exceptions
NullPointerException:
if c is null
Since
1.6
See Also
javax.swing.JComponent#getBaseline(int, int)
getButtonListenerback to summary
private BasicButtonListener getButtonListener(AbstractButton b)

Returns the ButtonListener for the passed in Button, or null if one could not be found.

getDefaultTextIconGapback to summary
public int getDefaultTextIconGap(AbstractButton b)

Returns the default gap between a text and an icon.

Parameters
b:AbstractButton

an abstract button

Returns:int

the default gap between text and an icon

getMaximumSizeback to summary
public Dimension getMaximumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

Doc from javax.swing.plaf.ComponentUI.getMaximumSize.

Returns the specified component's maximum size appropriate for the look and feel. If null is returned, the maximum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes getPreferredSize and returns that value.

getMinimumSizeback to summary
public Dimension getMinimumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

Doc from javax.swing.plaf.ComponentUI.getMinimumSize.

Returns the specified component's minimum size appropriate for the look and feel. If null is returned, the minimum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes getPreferredSize and returns that value.

getPreferredSizeback to summary
public Dimension getPreferredSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

Doc from javax.swing.plaf.ComponentUI.getPreferredSize.

Returns the specified component's preferred size appropriate for the look and feel. If null is returned, the preferred size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method returns null.

getPropertyPrefixback to summary
protected String getPropertyPrefix()

Returns the property prefix.

Returns:String

the property prefix

getTextShiftOffsetback to summary
protected int getTextShiftOffset()

Returns the offset of the text.

Returns:int

the offset of the text

installDefaultsback to summary
protected void installDefaults(AbstractButton b)

Installs default properties.

Parameters
b:AbstractButton

an abstract button

installKeyboardActionsback to summary
protected void installKeyboardActions(AbstractButton b)

Registers keyboard actions.

Parameters
b:AbstractButton

an abstract button

installListenersback to summary
protected void installListeners(AbstractButton b)

Registers listeners.

Parameters
b:AbstractButton

an abstract button

installUIback to summary
public void installUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.installUI.

Doc from javax.swing.plaf.ComponentUI.installUI.

Configures the specified component appropriately for the look and feel. This method is invoked when the ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:

  1. Install default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
  2. Install a LayoutManager on the component if necessary.
  3. Create/add any required sub-components to the component.
  4. Create/install event listeners on the component.
  5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
  6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
  7. Initialize any appropriate instance data.
isValidToggleButtonObjback to summary
private boolean isValidToggleButtonObj(Object obj)
layoutback to summary
private String layout(AbstractButton b, FontMetrics fm, int width, int height)
paintback to summary
public void paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.paint.

Doc from javax.swing.plaf.ComponentUI.paint.

Paints the specified component appropriately for the look and feel. This method is invoked from the ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified Graphics object to render the content of the component.

paintButtonPressedback to summary
protected void paintButtonPressed(Graphics g, AbstractButton b)

Paints a pressed button.

Parameters
g:Graphics

an instance of Graphics

b:AbstractButton

an abstract button

paintFocusback to summary
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect)

Paints a focused button.

Parameters
g:Graphics

an instance of Graphics

b:AbstractButton

an abstract button

viewRect:Rectangle

a bounding rectangle to render the button

textRect:Rectangle

a bounding rectangle to render the text

iconRect:Rectangle

a bounding rectangle to render the icon

paintIconback to summary
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect)

Paints an icon of the current button.

Parameters
g:Graphics

an instance of Graphics

c:JComponent

a component

iconRect:Rectangle

a bounding rectangle to render the icon

paintTextback to summary
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text)

Method which renders the text of the current button. As of Java 2 platform v 1.4 this method should not be used or overridden. Use the paintText method which takes the AbstractButton argument.

Parameters
g:Graphics

an instance of Graphics

c:JComponent

a component

textRect:Rectangle

a bounding rectangle to render the text

text:String

a string to render

paintTextback to summary
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text)

Method which renders the text of the current button.

Parameters
g:Graphics

Graphics context

b:AbstractButton

Current button to render

textRect:Rectangle

Bounding rectangle to render the text

text:String

String to render

Since
1.4
selectToggleButtonback to summary
private void selectToggleButton(ActionEvent event, boolean next)

Select toggle button based on "Previous" or "Next" operation

setTextShiftOffsetback to summary
protected void setTextShiftOffset()

Sets the offset of the text.

uninstallDefaultsback to summary
protected void uninstallDefaults(AbstractButton b)

Uninstalls default properties.

Parameters
b:AbstractButton

an abstract button

uninstallKeyboardActionsback to summary
protected void uninstallKeyboardActions(AbstractButton b)

Unregisters keyboard actions.

Parameters
b:AbstractButton

an abstract button

uninstallListenersback to summary
protected void uninstallListeners(AbstractButton b)

Unregisters listeners.

Parameters
b:AbstractButton

an abstract button

uninstallUIback to summary
public void uninstallUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

Doc from javax.swing.plaf.ComponentUI.uninstallUI.

Reverses configuration which was done on the specified component during installUI. This method is invoked when this UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in installUI, being careful to leave the JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:

  1. Remove any UI-set borders from the component.
  2. Remove any UI-set layout managers on the component.
  3. Remove any UI-added sub-components from the component.
  4. Remove any UI-added event/property listeners from the component.
  5. Remove any UI-installed keyboard UI from the component.
  6. Nullify any allocated instance data objects to allow for GC.
javax.swing.plaf.basic back to summary

private Class BasicButtonUI.ButtonGroupInfo

extends Object
Class Inheritance

ButtonGroupInfo, used to get related info in button group for given toggle button

Field Summary

Modifier and TypeField and Description
pack-priv JToggleButton
pack-priv HashSet<JToggleButton>
pack-priv JToggleButton
pack-priv JToggleButton
pack-priv JToggleButton
pack-priv JToggleButton
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
pack-priv boolean
pack-priv Component
pack-priv void
jumpToNextComponent(boolean next)

Find the button group the passed in JToggleButton belongs to, and move focus to next component of the last button in the group or previous component of first button

pack-priv void
selectNewButton(boolean next)

Find the new toggle/radio button that focus needs to be moved to in the group, select the button In case of radio button, setPressed and setArmed is called on the button model, so that Action set on button is performed on selecting the button

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeBtnback to summary
pack-priv JToggleButton activeBtn
btnsInGroupback to summary
pack-priv HashSet<JToggleButton> btnsInGroup
firstBtnback to summary
pack-priv JToggleButton firstBtn
lastBtnback to summary
pack-priv JToggleButton lastBtn
nextBtnback to summary
pack-priv JToggleButton nextBtn
previousBtnback to summary
pack-priv JToggleButton previousBtn
srcFoundback to summary
pack-priv boolean srcFound

Constructor Detail

ButtonGroupInfoback to summary
public ButtonGroupInfo(JToggleButton btn)

Method Detail

containsInGroupback to summary
pack-priv boolean containsInGroup(Object obj)
getButtonGroupInfoback to summary
pack-priv boolean getButtonGroupInfo()
getFocusTransferBaseComponentback to summary
pack-priv Component getFocusTransferBaseComponent(boolean next)
jumpToNextComponentback to summary
pack-priv void jumpToNextComponent(boolean next)

Find the button group the passed in JToggleButton belongs to, and move focus to next component of the last button in the group or previous component of first button

selectNewButtonback to summary
pack-priv void selectNewButton(boolean next)

Find the new toggle/radio button that focus needs to be moved to in the group, select the button In case of radio button, setPressed and setArmed is called on the button model, so that Action set on button is performed on selecting the button

javax.swing.plaf.basic back to summary

private Class BasicButtonUI.KeyHandler

extends Object
implements KeyListener
Class Inheritance
All Implemented Interfaces
java.awt.event.KeyListener, java.util.EventListener

Togglebutton KeyListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private boolean
public void
keyPressed(KeyEvent e)

Implements java.awt.event.KeyListener.keyPressed.

Invoked when a key has been pressed.

public void
keyReleased(KeyEvent e)

Implements java.awt.event.KeyListener.keyReleased.

Invoked when a key has been released.

public void
keyTyped(KeyEvent e)

Implements java.awt.event.KeyListener.keyTyped.

Invoked when a key has been typed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

KeyHandlerback to summary
private KeyHandler()

Method Detail

isFocusTraversalKeyback to summary
private boolean isFocusTraversalKey(JComponent c, int id, AWTKeyStroke stroke)
keyPressedback to summary
public void keyPressed(KeyEvent e)

Implements java.awt.event.KeyListener.keyPressed.

Doc from java.awt.event.KeyListener.keyPressed.

Invoked when a key has been pressed. See the class description for KeyEvent for a definition of a key pressed event.

keyReleasedback to summary
public void keyReleased(KeyEvent e)

Implements java.awt.event.KeyListener.keyReleased.

Doc from java.awt.event.KeyListener.keyReleased.

Invoked when a key has been released. See the class description for KeyEvent for a definition of a key released event.

keyTypedback to summary
public void keyTyped(KeyEvent e)

Implements java.awt.event.KeyListener.keyTyped.

Doc from java.awt.event.KeyListener.keyTyped.

Invoked when a key has been typed. See the class description for KeyEvent for a definition of a key typed event.

javax.swing.plaf.basic back to summary

private Class BasicButtonUI.SelectNextBtn

extends AbstractAction
Class Inheritance
Annotations
@SuppressWarnings:serial

Field Summary

Inherited from javax.swing.AbstractAction:
changeSupportenabled

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Inherited from javax.swing.AbstractAction:
addPropertyChangeListenerclonefirePropertyChangegetKeysgetPropertyChangeListenersgetValueisEnabledputValueremovePropertyChangeListenersetEnabled

Constructor Detail

SelectNextBtnback to summary
public SelectNextBtn()

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

javax.swing.plaf.basic back to summary

private Class BasicButtonUI.SelectPreviousBtn

extends AbstractAction
Class Inheritance
Annotations
@SuppressWarnings:serial

Field Summary

Inherited from javax.swing.AbstractAction:
changeSupportenabled

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

Inherited from javax.swing.AbstractAction:
addPropertyChangeListenerclonefirePropertyChangegetKeysgetPropertyChangeListenersgetValueisEnabledputValueremovePropertyChangeListenersetEnabled

Constructor Detail

SelectPreviousBtnback to summary
public SelectPreviousBtn()

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.