java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JMenuItem
javax.swing.JMenu
com.iamsoft.util.ui.swing.LafMenu
- All Implemented Interfaces:
ImageObserver,ItemSelectable,MenuContainer,Serializable,Accessible,MenuElement,SwingConstants
Allow user to change look and feel of Swing app on the fly. Selections can
be persisted to backing store so that changes affect subsequent sessions.
Manually call resetLaf() to initialize application look and feel.
Extended applet available
To test LAFs with ANT, try something like:
<java classname="com.iamsoft.util.ui.swing.LafMenu" fork="true">
<classpath>
<pathelement location="${libDir}"/>
<pathelement location="${log4jDir}/dist/lib/log4j-1.2.8.jar"/>
<pathelement location="${java.home}/demo/jfc/SwingSet2/SwingSet2.jar"/>
<fileset dir="${lafsDir}" includes="*.jar"/>
</classpath>
<arg value="swingset"/>
</java>
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn applet that demonstrates how to use rearrangeable models.classNested classes/interfaces inherited from class javax.swing.JMenu
JMenu.AccessibleJMenu, JMenu.WinListenerNested classes/interfaces inherited from class javax.swing.JMenuItem
JMenuItem.AccessibleJMenuItemNested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListenerNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionUnmodifiable set of look and feels we can try to make available.Fields inherited from class javax.swing.JMenu
popupListenerFields inherited from class javax.swing.AbstractButton
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_PROPERTYFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST -
Constructor Summary
ConstructorsConstructorDescriptionLafMenu()LafMenu(Preferences pPrefNode) LafMenu(Preferences pPrefNode, Set<String> pLookAndFeels) LafMenu(Preferences pPrefNode, Set<String> pLookAndFeels, Collection<? extends Component> pWidgets) By default, constructing menu will not update UIManager LAF. -
Method Summary
Modifier and TypeMethodDescriptionLAF to use if nothing specified in backing store.protected intgetInsertionIdx(JRadioButtonMenuItem pLafItem) Determine where new LAF should be inserted into menu.Key used to store LAF info (in Windows registry or equivalent backing store).Where LAF info will be stored persistently.Collection<? extends Component>Set of components to be updated when look and feel changes.static voidDisplay a simple frame to test menu.voidresetLaf()Update LAF for UIManager and widgets.voidresetLaf(boolean pUpdateWidgets) Update look and feel based on data in backing store (or default LAF if backing store data unavailable).voidsetDefaultLaf(String pDefaultLaf) protected voidsetLookAndFeel(String pClassName) Update look and feel in UIManager and all components in collection.voidsetPrefKey(String pPrefKey) voidsetPrefNode(Preferences pPrefNode) voidsetWidgets(Collection<? extends Component> pWidgets) Methods inherited from class javax.swing.JMenu
add, add, add, add, add, addMenuListener, addSeparator, applyComponentOrientation, createActionChangeListener, createActionComponent, createWinListener, doClick, fireMenuCanceled, fireMenuDeselected, fireMenuSelected, getAccessibleContext, getComponent, getDelay, getItem, getItemCount, getMenuComponent, getMenuComponentCount, getMenuComponents, getMenuListeners, getPopupMenu, getPopupMenuOrigin, getSubElements, getUIClassID, insert, insert, insert, insertSeparator, isMenuComponent, isPopupMenuVisible, isSelected, isTearOff, isTopLevelMenu, menuSelectionChanged, paramString, processKeyEvent, remove, remove, remove, removeAll, removeMenuListener, setAccelerator, setComponentOrientation, setDelay, setMenuLocation, setModel, setPopupMenuVisible, setSelected, updateUIMethods inherited from class javax.swing.JMenuItem
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getMenuDragMouseListeners, getMenuKeyListeners, init, isArmed, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setArmed, setEnabled, setUIMethods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, fireActionPerformed, 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, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPositionMethods inherited from class javax.swing.JComponent
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, 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, updateMethods inherited from class java.awt.Container
add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, 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, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javax.swing.MenuElement
processKeyEvent, processMouseEvent
-
Field Details
-
POTENTIAL_LOOK_AND_FEELS
Unmodifiable set of look and feels we can try to make available. To limit or extend available LAFs, add or remove class names. By default, this set includes all installed look and feels plus a few others. To request support for additional look and feels, e-mail info@iamsoft.com. If this set is updated after some menus are instantiated, the premature menus will not reflect the updates. Actually, the set is unmodifiable so some of the preceding makes no sense (TODO).- See Also:
-
- Javootoo
- 3-D
- A03
- Alloy
- BizLaf
- Compiere
- EaSynth
- FH
- GtkSwing
- Hippo
- InfoNode
- JGoodies Windows, Plastic, Plastic 3-D, Plastic XP
- Joxy
- Kunststoff
- LipstikLF
- Liquid
- Metouia
- Napkin
- NextStep
- NimROD
- Office
- Oyoaha
- Pgs
- Quaqua
- Seaglass
- Simple
- Skin
- Smart (screws everything up)
- SmoothMetal
- Squareness
- Substance
- Synthetica
- Teknolust
- Tiny
- Tonic
- Web
- XP
-
-
Constructor Details
-
LafMenu
public LafMenu() -
LafMenu
-
LafMenu
-
LafMenu
public LafMenu(Preferences pPrefNode, Set<String> pLookAndFeels, Collection<? extends Component> pWidgets) By default, constructing menu will not update UIManager LAF.- Parameters:
pPrefNode- Preferences node used to persist look and feel in between invocations.pLookAndFeels- Set of 'look and feel' implementation class names.pWidgets- Components to be updated when LAF changes.
-
-
Method Details
-
getWidgets
Set of components to be updated when look and feel changes. If null, all components are updated. -
setWidgets
-
getPrefNode
Where LAF info will be stored persistently. If null (the default), data will not be persisted between invocations. Use a user node so that each login may be associated with a different LAF.- See Also:
-
setPrefNode
-
getPrefKey
Key used to store LAF info (in Windows registry or equivalent backing store). If the default is used, there may be overlap between applications. Set to null to prevent persisent updates. Defaults to 'laf'.- See Also:
-
setPrefKey
-
getDefaultLaf
LAF to use if nothing specified in backing store. Defaults to system look and feel. -
setDefaultLaf
-
getInsertionIdx
Determine where new LAF should be inserted into menu. Attempts to organize LAFs alphabetically. Manually altering menu item order can make this method behave strangely. -
resetLaf
public void resetLaf() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelExceptionUpdate LAF for UIManager and widgets. -
resetLaf
public void resetLaf(boolean pUpdateWidgets) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException Update look and feel based on data in backing store (or default LAF if backing store data unavailable). If this is called before GUI items are constructed, use 'false' as argument.resetLaf(false)should be called as soon as possible since Swing widget sometimes look screwy when the LAF is changed after they've been instantiated.- Parameters:
pUpdateWidgets- If false, only update UIManager.- Throws:
ClassNotFoundExceptionInstantiationExceptionIllegalAccessExceptionUnsupportedLookAndFeelException
-
setLookAndFeel
protected void setLookAndFeel(String pClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException Update look and feel in UIManager and all components in collection.- Parameters:
pClassName- Name of candidate look and feel class.- Throws:
ClassNotFoundExceptionInstantiationExceptionIllegalAccessExceptionUnsupportedLookAndFeelException- See Also:
-
main
Display a simple frame to test menu. Pass arg 'swingset' to see menu added to Java swingset demo (must include JAR in classpath).- Parameters:
pLookAndFeels- Look and feels.
-