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
,java.awt.image.ImageObserver
,java.awt.ItemSelectable
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
,javax.swing.MenuElement
,javax.swing.SwingConstants
- Direct Known Subclasses:
JideSplitButton
public class JideMenu extends javax.swing.JMenu implements Alignable
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.
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.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"); } });
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
JideMenu.MenuCreator
Deprecated.The createMenu method of MenuCreator should JPopupMenu as parameter.static interface
JideMenu.PopupMenuCustomizer
Customizes the popup menu.static interface
JideMenu.PopupMenuOriginCalculator
Calculates the origin of the popup menu if specified.-
Nested classes/interfaces inherited from class javax.swing.JMenu
javax.swing.JMenu.AccessibleJMenu, javax.swing.JMenu.WinListener
-
Nested classes/interfaces inherited from class javax.swing.JMenuItem
javax.swing.JMenuItem.AccessibleJMenuItem
-
Nested classes/interfaces inherited from class javax.swing.AbstractButton
javax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListener
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description static int
DELAY
-
Fields 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_PROPERTY
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface com.jidesoft.swing.Alignable
PROPERTY_ORIENTATION
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description JideMenu.MenuCreator
getMenuCreator()
Deprecated.useJideMenu.PopupMenuCustomizer
andgetPopupMenuCustomizer()
instead.int
getOrientation()
Gets the orientation.JideMenu.PopupMenuOriginCalculator
getOriginCalculator()
Gets the PopupMenuOriginCalculator ornull
, if none has been specified.JideMenu.PopupMenuCustomizer
getPopupMenuCustomizer()
Gets the PopupMenuCustomizer.protected java.awt.Point
getPopupMenuOrigin()
int
getPreferredPopupHorizontalAlignment()
int
getPreferredPopupVerticalAlignment()
protected void
hideMenu()
protected void
initMenu()
boolean
isOpaque()
Checks if theboolean
isTopLevelMenu()
Checks if the menu is added to a top level menu container.boolean
originalIsOpaque()
void
setMenuCreator(JideMenu.MenuCreator menuCreator)
Deprecated.void
setOrientation(int orientation)
Changes the orientation.void
setOriginCalculator(JideMenu.PopupMenuOriginCalculator originCalculator)
Sets the PopupMenuOriginCalculator that will be used to determine the popup menu origin.void
setPopupMenuCustomizer(JideMenu.PopupMenuCustomizer customizer)
Sets the PopupMenuCustomizer.void
setPopupMenuVisible(boolean b)
void
setPreferredPopupHorizontalAlignment(int preferredPopupHorizontalAlignment)
void
setPreferredPopupVerticalAlignment(int preferredPopupVerticalAlignment)
protected boolean
shouldHidePopupMenu()
Check if the popup menu should stay hidden althoughsetPopupMenuVisible(boolean)
is invoked.boolean
supportHorizontalOrientation()
Checks if the component support horizontal orientation.boolean
supportVerticalOrientation()
Checks 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, updateUI
-
Methods 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, setUI
-
Methods 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, setVerticalTextPosition
-
Methods 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, update
-
Methods 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, validateTree
-
Methods 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, transferFocusUpCycle
-
-
-
-
Method Detail
-
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:
isTopLevelMenu
in classjavax.swing.JMenu
- Returns:
- true if it's top level menu.
-
getOriginCalculator
public JideMenu.PopupMenuOriginCalculator getOriginCalculator()
Gets the PopupMenuOriginCalculator ornull
, if none has been specified.- Returns:
- the calculator
-
setOriginCalculator
public void setOriginCalculator(JideMenu.PopupMenuOriginCalculator originCalculator)
Sets the PopupMenuOriginCalculator that will be used to determine the popup menu origin.- Parameters:
originCalculator
- the calculator
-
getMenuCreator
@Deprecated public JideMenu.MenuCreator getMenuCreator()
Deprecated.useJideMenu.PopupMenuCustomizer
andgetPopupMenuCustomizer()
instead.Gets the MenuCreator.- Returns:
- the MenuCreator.
-
setMenuCreator
@Deprecated public void setMenuCreator(JideMenu.MenuCreator menuCreator)
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
public JideMenu.PopupMenuCustomizer getPopupMenuCustomizer()
Gets the PopupMenuCustomizer.- Returns:
- the PopupMenuCustomizer.
-
setPopupMenuCustomizer
public void setPopupMenuCustomizer(JideMenu.PopupMenuCustomizer customizer)
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 of
You 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
protected java.awt.Point getPopupMenuOrigin()
- Overrides:
getPopupMenuOrigin
in classjavax.swing.JMenu
-
isOpaque
public boolean isOpaque()
Checks if the- Overrides:
isOpaque
in classjavax.swing.JComponent
- 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:Alignable
Checks if the component support vertical orientation. doesn't consider the component orientation, it should return false.- Specified by:
supportVerticalOrientation
in interfaceAlignable
- Returns:
- true if it supports vertical orientation
-
supportHorizontalOrientation
public boolean supportHorizontalOrientation()
Description copied from interface:Alignable
Checks if the component support horizontal orientation.- Specified by:
supportHorizontalOrientation
in interfaceAlignable
- Returns:
- true if it supports horizontal orientation
-
setOrientation
public void setOrientation(int orientation)
Description copied from interface:Alignable
Changes the orientation. If the component is a Swing component, the default implementation is this.JideSwingUtilities.setOrientationOf(this, orientation);
- Specified by:
setOrientation
in interfaceAlignable
- Parameters:
orientation
- the new orientation
-
getOrientation
public int getOrientation()
Description copied from interface:Alignable
Gets the orientation. If the component is a Swing component, the default implementation is this.return JideSwingUtilities.getOrientationOf(this);
- Specified by:
getOrientation
in interfaceAlignable
- Returns:
- orientation
-
setPopupMenuVisible
public void setPopupMenuVisible(boolean b)
- Overrides:
setPopupMenuVisible
in classjavax.swing.JMenu
-
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.
-
-