public class JXHyperlink extends JButton
This button has visual state related to a notion of "clicked":
foreground color is unclickedColor or clickedColor depending on
its boolean bound property clicked being false or true, respectively.
If the hyperlink has an action, it guarantees to synchronize its
"clicked" state to an action value with key LinkAction.VISITED_KEY.
Synchronization happens on setAction() and on propertyChange notification
from the action. JXHyperlink accepts any type of action -
AbstractHyperlinkAction
is a convenience implementation to
simplify clicked control.
LinkAction linkAction = new LinkAction("http://swinglabs.org") {
public void actionPerformed(ActionEvent e) {
doSomething(getTarget());
setVisited(true);
}
};
JXHyperlink hyperlink = new JXHyperlink(linkAction);
The hyperlink can be configured to always update its clicked
property after firing the actionPerformed:
JXHyperlink hyperlink = new JXHyperlink(action);
hyperlink.setOverrulesActionOnClick(true);
By default, this property is false. The hyperlink will
auto-click only if it has no action. Developers can change the
behaviour by overriding isAutoSetClicked()
;JButton.AccessibleJButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private Color |
clickedColor
Color for the hyper link if it has already been clicked.
|
private boolean |
hasBeenVisited |
private boolean |
overrulesActionOnClick |
static String |
uiClassID |
private Color |
unclickedColor
Color for the hyper link if it has not yet been clicked.
|
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JXHyperlink()
Creates a new instance of JXHyperlink with default parameters
|
JXHyperlink(Action action)
Creates a new instance of JHyperLink and configures it from provided Action.
|
Modifier and Type | Method and Description |
---|---|
private void |
configureClickedPropertyFromAction(Action a) |
protected void |
configurePropertiesFromAction(Action a)
Read all the essential properties from the provided
Action
and apply it to the JXHyperlink |
protected PropertyChangeListener |
createActionPropertyChangeListener(Action a)
Creates and returns a listener that will watch the changes of the
provided
Action and will update JXHyperlink's properties
accordingly. |
protected void |
fireActionPerformed(ActionEvent event)
Overridden to respect the overrulesActionOnClick property.
|
Color |
getClickedColor()
Returns the foreground color for visited links.
|
boolean |
getOverrulesActionOnClick()
Returns a boolean indicating whether the clicked property should be set
always on clicked.
|
String |
getUIClassID()
Returns a string that specifies the name of the L&F class
that renders this component.
|
Color |
getUnclickedColor()
Returns the foreground color for unvisited links.
|
private void |
init() |
protected boolean |
isAutoSetClicked()
Returns a boolean indicating whether the clicked property should be set
after firing action events.
|
boolean |
isClicked()
Returns a boolean indicating if this link has already been visited.
|
void |
setClicked(boolean clicked)
Sets the clicked property and updates visual state depending on clicked.
|
void |
setClickedColor(Color color)
Sets the color for the previously visited link.
|
void |
setOverrulesActionOnClick(boolean overrule)
Sets the overrulesActionOnClick property.
|
void |
setUnclickedColor(Color color)
Sets the color for the previously not visited link.
|
void |
setURI(URI uri)
Convenience method to create and install a HyperlinkAction for the given URI.
|
void |
updateUI()
Notification from the
UIManager that the L&F has changed. |
getAccessibleContext, isDefaultButton, isDefaultCapable, paramString, removeNotify, setDefaultCapable
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createChangeListener, createItemListener, doClick, doClick, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private boolean hasBeenVisited
private Color unclickedColor
private Color clickedColor
private boolean overrulesActionOnClick
public JXHyperlink()
public JXHyperlink(Action action)
action
- Action whose parameters will be borrowed to configure newly
created JXHyperLinkpublic void setURI(URI uri)
uri
- to uri to create a HyperlinkAction for, maybe null.HeadlessException
- if GraphicsEnvironment.isHeadless()
returns true
UnsupportedOperationException
- if the current platform doesn't support DesktopHyperlinkAction.createHyperlinkAction(URI)
public Color getUnclickedColor()
public void setClickedColor(Color color)
color
- Color for the hyper link if it has already been clicked.public Color getClickedColor()
public void setUnclickedColor(Color color)
color
- Color for the hyper link if it has not yet been clicked.public void setClicked(boolean clicked)
NOTE: as with all button's visual properties, this will not update the backing action's "visited" state.
clicked
- flag to indicate if the button should be regarded as
having been clicked or not.isClicked()
public boolean isClicked()
true
if hyper link has already been clicked.setClicked(boolean)
public void setOverrulesActionOnClick(boolean overrule)
The default value is false
.
overrule
- if true, fireActionPerformed will set clicked to true
independent of action.getOverrulesActionOnClick()
,
setClicked(boolean)
public boolean getOverrulesActionOnClick()
setOverrulesActionOnClick(boolean)
,
setClicked(boolean)
protected void fireActionPerformed(ActionEvent event)
Overridden to respect the overrulesActionOnClick property.
fireActionPerformed
in class AbstractButton
protected boolean isAutoSetClicked()
protected PropertyChangeListener createActionPropertyChangeListener(Action a)
Action
and will update JXHyperlink's properties
accordingly.createActionPropertyChangeListener
in class AbstractButton
protected void configurePropertiesFromAction(Action a)
Action
and apply it to the JXHyperlink
configurePropertiesFromAction
in class AbstractButton
private void configureClickedPropertyFromAction(Action a)
private void init()
public String getUIClassID()
getUIClassID
in class JButton
public void updateUI()
UIManager
that the L&F has changed.
Replaces the current UI object with the latest version from the UIManager
.updateUI
in class JButton
JComponent.updateUI()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses