public class JideMenu extends javax.swing.JMenu implements Alignable
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
JideMenu.MenuCreator
Deprecated.
The createMenu method of MenuCreator should JPopupMenu as parameter. Since it's a public API we have
to deprecated this one and ask users to use
JideMenu.PopupMenuCustomizer instead. |
static interface |
JideMenu.PopupMenuCustomizer
Customizes the popup menu.
|
static interface |
JideMenu.PopupMenuOriginCalculator
Calculates the origin of the popup menu if specified.
|
javax.swing.JMenu.AccessibleJMenu, javax.swing.JMenu.WinListenerjavax.swing.JMenuItem.AccessibleJMenuItemjavax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListenerjavax.swing.JComponent.AccessibleJComponent| Modifier and Type | Field and Description |
|---|---|
static int |
DELAY |
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_PROPERTYlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTPROPERTY_ORIENTATION| Constructor and Description |
|---|
JideMenu() |
JideMenu(javax.swing.Action a) |
JideMenu(java.lang.String s) |
JideMenu(java.lang.String s,
boolean b) |
| Modifier and Type | Method and Description |
|---|---|
JideMenu.MenuCreator |
getMenuCreator()
Deprecated.
use
JideMenu.PopupMenuCustomizer and getPopupMenuCustomizer() instead. |
int |
getOrientation()
Gets the orientation.
|
JideMenu.PopupMenuOriginCalculator |
getOriginCalculator()
Gets the PopupMenuOriginCalculator or
null, 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 the
|
boolean |
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 although
setPopupMenuVisible(boolean) is invoked. |
boolean |
supportHorizontalOrientation()
Checks if the component support horizontal orientation.
|
boolean |
supportVerticalOrientation()
Checks if the component support vertical orientation.
|
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, updateUIactionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getMenuDragMouseListeners, getMenuKeyListeners, init, isArmed, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setArmed, setEnabled, setUIaddActionListener, 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, setVerticalTextPositionaddAncestorListener, 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, updateadd, 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, validateTreeaction, 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, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic JideMenu()
public JideMenu(java.lang.String s)
public JideMenu(javax.swing.Action a)
public JideMenu(java.lang.String s,
boolean b)
protected void initMenu()
public boolean isTopLevelMenu()
isTopLevelMenu in class javax.swing.JMenupublic JideMenu.PopupMenuOriginCalculator getOriginCalculator()
null, if none has been specified.public void setOriginCalculator(JideMenu.PopupMenuOriginCalculator originCalculator)
originCalculator - the calculator@Deprecated public JideMenu.MenuCreator getMenuCreator()
JideMenu.PopupMenuCustomizer and getPopupMenuCustomizer() instead.@Deprecated public void setMenuCreator(JideMenu.MenuCreator menuCreator)
JideMenu.PopupMenuCustomizer and setPopupMenuCustomizer(com.jidesoft.swing.JideMenu.PopupMenuCustomizer)
instead.menuCreator - he menu creatorpublic JideMenu.PopupMenuCustomizer getPopupMenuCustomizer()
public void setPopupMenuCustomizer(JideMenu.PopupMenuCustomizer customizer)
JideMenu menu = new JideMenu();
menu.add(new JMenuItem("..."));
menu.add(new JMenuItem("..."));
You can do
JideMenu menu = new JideMenu();
menu.setPopupMenuCustomzier(new JideMenu.PopupMenuCustomizer() {
void customize(JPopupMenu popupMenu) {
poupMenu.removeAll();
popupMenu.add(new JMenuItem("..."));
popupMenu.add(new JMenuItem("..."));
}
}
If the menu is never used, the two add methods will never be called thus improve the performance.customizer - the popup menu customizerprotected java.awt.Point getPopupMenuOrigin()
getPopupMenuOrigin in class javax.swing.JMenupublic boolean isOpaque()
isOpaque in class javax.swing.JComponentpublic boolean originalIsOpaque()
protected void hideMenu()
public int getPreferredPopupHorizontalAlignment()
public void setPreferredPopupHorizontalAlignment(int preferredPopupHorizontalAlignment)
public int getPreferredPopupVerticalAlignment()
public void setPreferredPopupVerticalAlignment(int preferredPopupVerticalAlignment)
public boolean supportVerticalOrientation()
AlignablesupportVerticalOrientation in interface Alignablepublic boolean supportHorizontalOrientation()
AlignablesupportHorizontalOrientation in interface Alignablepublic void setOrientation(int orientation)
AlignableJideSwingUtilities.setOrientationOf(this, orientation);setOrientation in interface Alignableorientation - the new orientationpublic int getOrientation()
Alignablereturn
JideSwingUtilities.getOrientationOf(this);getOrientation in interface Alignablepublic void setPopupMenuVisible(boolean b)
setPopupMenuVisible in class javax.swing.JMenuprotected boolean shouldHidePopupMenu()
setPopupMenuVisible(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.