Package com.jidesoft.swing
Class JideMenu
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JMenuItem
javax.swing.JMenu
com.jidesoft.swing.JideMenu
- All Implemented Interfaces:
Alignable,ImageObserver,ItemSelectable,MenuContainer,Serializable,Accessible,MenuElement,SwingConstants
- Direct Known Subclasses:
JideSplitButton
A special implementation of JMenu. It is used to replace JMenu in order to use with CommandBar.
It has two special features. First, it has a PopupMenuCustomizer for lazy menu creation. Instead of creating menu upfront which might be quite expensive, you can create it using PopupMenuCustomizer. PopupMenuCustomizer is called before the menu is set visible. Please note, when you use PopupMenuCustomizer, you need to remove the old menu items you added previously using PopupMenuCustomizer. Otherwise, you will see a menu which gets longer and longer when you show it. See below for an example.
It has two special features. First, it has a PopupMenuCustomizer for lazy menu creation. Instead of creating menu upfront which might be quite expensive, you can create it using PopupMenuCustomizer. PopupMenuCustomizer is called before the menu is set visible. Please note, when you use PopupMenuCustomizer, you need to remove the old menu items you added previously using PopupMenuCustomizer. Otherwise, you will see a menu which gets longer and longer when you show it. See below for an example.
JideMenu jideMenu = new JideMenu("Dynamic");
jideMenu.setPopupMenuCustomizer(new JideMenu.PopupMenuCustomizer(){
public void customize(JPopupMenu menu) {
menu.add("item 1");
menu.add("item 2");
menu.add("item 3");
menu.add("item 4");
menu.add("item 5");
}
});
Second feature is popup alignment. Usually menu and its popup align to the left side. In our case, we hope they align
to right side. So we added a method call setPreferredPopupHorizontalAlignment(). You can set to RIGHT if you want
to.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.The createMenu method of MenuCreator should JPopupMenu as parameter.static interfaceCustomizes the popup menu.static interfaceCalculates the origin of the popup menu if specified.Nested 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
FieldsFields 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 com.jidesoft.swing.Alignable
PROPERTY_ORIENTATIONFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.useJideMenu.PopupMenuCustomizerandgetPopupMenuCustomizer()instead.intGets the orientation.Gets the PopupMenuOriginCalculator ornull, if none has been specified.Gets the PopupMenuCustomizer.protected Pointintintprotected voidhideMenu()protected voidinitMenu()booleanisOpaque()Checks if thebooleanChecks if the menu is added to a top level menu container.booleanvoidsetMenuCreator(JideMenu.MenuCreator menuCreator) Deprecated.voidsetOrientation(int orientation) Changes the orientation.voidsetOriginCalculator(JideMenu.PopupMenuOriginCalculator originCalculator) Sets the PopupMenuOriginCalculator that will be used to determine the popup menu origin.voidsetPopupMenuCustomizer(JideMenu.PopupMenuCustomizer customizer) Sets the PopupMenuCustomizer.voidsetPopupMenuVisible(boolean b) voidsetPreferredPopupHorizontalAlignment(int preferredPopupHorizontalAlignment) voidsetPreferredPopupVerticalAlignment(int preferredPopupVerticalAlignment) protected booleanCheck if the popup menu should stay hidden althoughsetPopupMenuVisible(boolean)is invoked.booleanChecks if the component support horizontal orientation.booleanChecks if the component support vertical orientation.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, getSubElements, getUIClassID, insert, insert, insert, insertSeparator, isMenuComponent, isPopupMenuVisible, isSelected, isTearOff, menuSelectionChanged, paramString, processKeyEvent, remove, remove, remove, removeAll, removeMenuListener, setAccelerator, setComponentOrientation, setDelay, setMenuLocation, setModel, 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, 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
-
DELAY
public static int DELAY
-
-
Constructor Details
-
JideMenu
public JideMenu() -
JideMenu
-
JideMenu
-
JideMenu
-
-
Method Details
-
initMenu
protected void initMenu() -
isTopLevelMenu
public boolean isTopLevelMenu()Checks if the menu is added to a top level menu container. It will be consider as top level menu when
1. getParent() equals null, or
2. getParent() is not an instance of JPopupMenu
Please note, the definition of topLevelMenu is different from that of JMenu.- Overrides:
isTopLevelMenuin classJMenu- Returns:
- true if it's top level menu.
-
getOriginCalculator
Gets the PopupMenuOriginCalculator ornull, if none has been specified.- Returns:
- the calculator
-
setOriginCalculator
Sets the PopupMenuOriginCalculator that will be used to determine the popup menu origin.- Parameters:
originCalculator- the calculator
-
getMenuCreator
Deprecated.useJideMenu.PopupMenuCustomizerandgetPopupMenuCustomizer()instead.Gets the MenuCreator.- Returns:
- the MenuCreator.
-
setMenuCreator
Deprecated.Sets the MenuCreator. MenuCreator can be used to do lazy menu creation. If you put code in the MenuCreator, it won't be called until before the menu is set visible.- Parameters:
menuCreator- he menu creator
-
getPopupMenuCustomizer
Gets the PopupMenuCustomizer.- Returns:
- the PopupMenuCustomizer.
-
setPopupMenuCustomizer
Sets the PopupMenuCustomizer. PopupMenuCustomizer can be used to do lazy menu creation. If you put code in the MenuCreator, it won't be called until before the menu is set visible. PopupMenuCustomizer has a customize method. The popup menu of this menu will be passed in. You can add/remove/change the menu items in customize method. For example, instead ofYou can doJideMenu menu = new JideMenu(); menu.add(new JMenuItem("...")); menu.add(new JMenuItem("..."));If the menu is never used, the two add methods will never be called thus improve the performance.JideMenu menu = new JideMenu(); menu.setPopupMenuCustomzier(new JideMenu.PopupMenuCustomizer() { void customize(JPopupMenu popupMenu) { poupMenu.removeAll(); popupMenu.add(new JMenuItem("...")); popupMenu.add(new JMenuItem("...")); } }- Parameters:
customizer- the popup menu customizer
-
getPopupMenuOrigin
- Overrides:
getPopupMenuOriginin classJMenu
-
isOpaque
public boolean isOpaque()Checks if the- Overrides:
isOpaquein classJComponent- Returns:
- false if it's top level menu. Otherwise, it will return what super.isOpaque().
-
originalIsOpaque
public boolean originalIsOpaque() -
hideMenu
protected void hideMenu() -
getPreferredPopupHorizontalAlignment
public int getPreferredPopupHorizontalAlignment() -
setPreferredPopupHorizontalAlignment
public void setPreferredPopupHorizontalAlignment(int preferredPopupHorizontalAlignment) -
getPreferredPopupVerticalAlignment
public int getPreferredPopupVerticalAlignment() -
setPreferredPopupVerticalAlignment
public void setPreferredPopupVerticalAlignment(int preferredPopupVerticalAlignment) -
supportVerticalOrientation
public boolean supportVerticalOrientation()Description copied from interface:AlignableChecks if the component support vertical orientation. doesn't consider the component orientation, it should return false.- Specified by:
supportVerticalOrientationin interfaceAlignable- Returns:
- true if it supports vertical orientation
-
supportHorizontalOrientation
public boolean supportHorizontalOrientation()Description copied from interface:AlignableChecks if the component support horizontal orientation.- Specified by:
supportHorizontalOrientationin interfaceAlignable- Returns:
- true if it supports horizontal orientation
-
setOrientation
public void setOrientation(int orientation) Description copied from interface:AlignableChanges the orientation. If the component is a Swing component, the default implementation is this.JideSwingUtilities.setOrientationOf(this, orientation);- Specified by:
setOrientationin interfaceAlignable- Parameters:
orientation- the new orientation
-
getOrientation
public int getOrientation()Description copied from interface:AlignableGets the orientation. If the component is a Swing component, the default implementation is this.return JideSwingUtilities.getOrientationOf(this);- Specified by:
getOrientationin interfaceAlignable- Returns:
- orientation
-
setPopupMenuVisible
public void setPopupMenuVisible(boolean b) - Overrides:
setPopupMenuVisiblein classJMenu
-
shouldHidePopupMenu
protected boolean shouldHidePopupMenu()Check if the popup menu should stay hidden althoughsetPopupMenuVisible(boolean)is invoked. The default implementation is to check if it contains any menu items. You could override this method to change the default behavior.- Returns:
- true if the popup menu should stay invisible. Otherwise false.
-