public class SmartIconJButton extends Object implements Icon, PropertyChangeListener
As JTabbedPanes cannot use any JComponents as tab selectors (the access if protected and we just have a label, an icon and a tooltip), we have to rely on tricks to bypass them.
This trick, the SmartIconJButton is an icon faking the behaviour of a button. It uses an Action for reacting to clicks and manages a set of images (default, rollover, pressed, disabled) to behave like a rollover button.
Modifier and Type | Field and Description |
---|---|
protected Action |
action
The action triggered when the clicks on the icon
|
protected Icon |
defaultIcon
the default icon (enabled/visible)
|
protected Icon |
disabledIcon
the icon for the disabled effect
|
protected Icon |
pressedIcon
the icno for the pressed effect
|
protected Icon |
rolloverIcon
the icon for the rollover effect
|
protected String |
tooltipText
the tooltip associated with the button
|
Constructor and Description |
---|
SmartIconJButton(Action action)
Constructs a new button with an action.
|
Modifier and Type | Method and Description |
---|---|
void |
fireAction(ActionEvent e)
triggers the associated action
|
Icon |
getDisabledIcon()
Returns the disabled icon
|
Icon |
getIcon()
Returns the default icon
|
int |
getIconHeight() |
int |
getIconWidth() |
Icon |
getPressedIcon()
Returns the pressed icon
|
Icon |
getRolloverIcon()
Returns the rollover icon
|
String |
getTooltipText() |
boolean |
isEnabled()
Returns the enabled state
|
boolean |
isPressed()
Returns the pressed state
|
boolean |
isRollover()
Returns the rollover state
|
boolean |
isVisible()
Returns the visible state
|
void |
paintIcon(Component c,
Graphics g,
int x,
int y)
paints the appropriate icon according to its internal state (pressed, rollover...)
|
void |
propertyChange(PropertyChangeEvent evt)
Do not call directly as it a side effect of listening to the action changes.
|
void |
setDisabledIcon(Icon icon)
Update the disabled icon property
|
void |
setEnabled(boolean isEnabled)
Update the enabled state
|
void |
setIcon(Icon icon)
Update the default icon property
|
void |
setPressed(boolean isPressed)
Update the pressed state
|
void |
setPressedIcon(Icon icon)
Update the pressed icon property
|
void |
setRollover(boolean isRollover)
Update the rollover state
|
void |
setRolloverIcon(Icon icon)
Update the rollover icon property
|
void |
setTooltipText(String tooltip) |
void |
setVisible(boolean isVisible)
Update the visible state
|
protected Action action
protected Icon defaultIcon
protected Icon rolloverIcon
protected Icon pressedIcon
protected Icon disabledIcon
protected String tooltipText
public SmartIconJButton(Action action)
public void setIcon(Icon icon)
public Icon getIcon()
public void setRolloverIcon(Icon icon)
public Icon getRolloverIcon()
public void setPressedIcon(Icon icon)
public Icon getPressedIcon()
public void setDisabledIcon(Icon icon)
public Icon getDisabledIcon()
public void setRollover(boolean isRollover)
public void setEnabled(boolean isEnabled)
public void setVisible(boolean isVisible)
public void setPressed(boolean isPressed)
public boolean isRollover()
public boolean isPressed()
public boolean isEnabled()
public boolean isVisible()
public void paintIcon(Component c, Graphics g, int x, int y)
public int getIconWidth()
getIconWidth
in interface Icon
public int getIconHeight()
getIconHeight
in interface Icon
public void fireAction(ActionEvent e)
public String getTooltipText()
public void setTooltipText(String tooltip)
public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
© Copyright 2004-2013 Lilian Chamontin. All Rights Reserved.