public class MenuItem extends TextBased
MenuBar to your Frame instance and
add MenuItems to it.
You can add other MenuItems to these and so on to create any structure of menu items. Also take a
look at the MenuSeparator which provides a non-clickable and slim line for separating
parts of the menu strip.
There is only this one class for every position in the menu tree.
MenuItems and MenuStrips can also be used to create menus that pop up when i.e. right-clicking on
something. This is accomplished by creating a ToolStrip and adding items to it. The ToolStrip can
be be shown by calling myToolStrip.show().Control.Constants, Control.ImageMode, Control.Predicate, Control.Predicate1<T>, Control.Predicate2<T,U>, Control.RenderingMethod, Control.Setter<T>FONT_SIZE, LINE_HEIGHT, TEXT_ALIGN, TEXT_ALIGN_Y, TEXT_COLORALL, ANCHOR_INACTIVE, AUTOSIZE_BOTH, AUTOSIZE_HEIGHT, AUTOSIZE_NONE, AUTOSIZE_WIDTH, BACKGROUND_COLOR, BACKGROUND_COLORS, BORDER, BORDER_COLOR, BORDER_RADIUS, BORDER_WIDTH, BUFFERED_RENDERING, COLORS, defaultRenderingMethod, FILL, FIT, FIT_INSIDE, FOREGROUND_COLOR, HOVER_COLOR, MARGIN, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT, MARGIN_TOP, name, OPACITY, PADDING, PADDING_BOTTOM, PADDING_LEFT, PADDING_RIGHT, PADDING_TOP, PERCENTAGE_MODE, PIXEL_MODE, PRESSED_COLOR, SPACING, TEXT_PROPERTIES, UNBUFFERED_RENDERING| Constructor and Description |
|---|
MenuItem() |
MenuItem(java.lang.String text) |
MenuItem(java.lang.String text,
Control.Predicate selectCallback)
Constructor for immediately setting text and a lambda function to call when this item is
selected.
|
MenuItem(java.lang.String text,
Control.Predicate selectCallback,
Shortcut shortcut)
Similar to
#MenuItem(String, Predicate), but also provide a shortcut. |
MenuItem(java.lang.String text,
java.lang.String selectCallback)
Constructor for immediately setting text and name of method to call when this item is selected.
|
MenuItem(java.lang.String text,
java.lang.String selectCallback,
Shortcut shortcut)
Similar to
MenuItem(String, String), but also provide a shortcut. |
MenuItem(java.lang.String text,
java.lang.String methodName,
Shortcut shortcut,
boolean strong)
If strong set to true, then the shortcut might also be fired when a textbox has focus.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(MenuItem... items)
Add subitems for this item.
|
void |
add(java.lang.String... strings)
Create and add subitems for each text String passed.
|
void |
clear()
Remove all subitems.
|
void |
close()
Close this item/strip.
|
MenuItem |
getItem(int index)
Get item at given index.
|
Control[] |
getItems()
Get sub items.
|
int |
getNumItems()
Get number of sub items.
|
Shortcut |
getShortcut() |
void |
insert(int position,
MenuItem... items)
Insert subitems at given position.
|
boolean |
isChecked() |
static void |
parseMenu(java.lang.String menuString,
ContextMenu contextMenu)
Same as
parseMenu(String, MenuBar) but for context menus. |
static void |
parseMenu(java.lang.String menuString,
ContextMenu contextMenu,
java.lang.String shortcutIntroduceSequence,
java.lang.String callbackIntroduceSequence) |
static void |
parseMenu(java.lang.String menuString,
MenuBar menubar)
Parse a string as menu.
|
static void |
parseMenu(java.lang.String menuString,
MenuBar menubar,
java.lang.String shortcutIntroduceSequence,
java.lang.String callbackIntroduceSequence) |
void |
remove(Control item)
Remove item.
|
void |
remove(int index)
Remove item at given index.
|
void |
removeChildSelectListener() |
void |
removeSelectListener() |
void |
setChecked(boolean checked)
MenuItems can be checked / unchecked with this method (little icon on the left of the MenuItem
text).
|
void |
setChildSelectListener(Control.Predicate lambda)
Set a listener for when a child of this header has been selected.
|
void |
setChildSelectListener(Control.Predicate1<MenuItem> lambda)
Set a listener for when a child of this header has been selected.
|
void |
setChildSelectListener(java.lang.String methodName) |
void |
setChildSelectListener(java.lang.String methodName,
java.lang.Object target)
Set a listener for when a child of this header has been selected.
|
void |
setEnabled(boolean enabled)
Set the enabled state of this element.
|
void |
setSelectListener(Control.Predicate lambda)
Set a listener lambda for when this item is selected.
|
void |
setSelectListener(Control.Predicate1<MenuItem> lambda)
Set a listener lambda for when this item is selected.
|
void |
setSelectListener(java.lang.String methodName) |
void |
setSelectListener(java.lang.String methodName,
java.lang.Object target)
Set a listener for the item selected event (called when this item has been selected).
|
void |
setShortcut(Shortcut shortcut)
Set the displayed shortcut (shortcut has no real effect unless set manually at Frame).
|
copyStyle, getFont, getFontSize, getLineHeight, getText, getTextAlign, getTextAlignY, getTextColor, isBold, isItalic, isStrikethrough, isUnderlined, setBold, setFont, setFontSize, setForegroundColor, setItalic, setLineHeight, setLineHeightPercent, setStrikethrough, setText, setText, setTextAlign, setTextAlignY, setTextColor, setUnderlinedaddAutoAnchors, animate, blur, copyStyle, doForAll, fillParent, fillParent, fillParent, fillParentHeight, fillParentHeight, fillParentWidth, fillParentWidth, focus, forceRepaint, getAnchorMode, getAnchorValue, getAvailableHeight, getAvailableWidth, getBackgroundColor, getBorderColor, getBorderRadius, getBorderWidth, getCursor, getForegroundColor, getHeight, getHoverColor, getImage, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOffsetXToParent, getOffsetXToWindow, getOffsetYToParent, getOffsetYToWindow, getOpacity, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getPressedColor, getVersionString, getWidth, getX, getY, getZ, isEnabled, isFocusable, isFocused, isPropagationStopped, isVisible, noAutosize, relativeCoordsAreWithin, removeAnchor, removeBoxShadow, removeFocusListener, removeMouseListener, removeResizeListener, setAnchor, setAnchors, setAutosizing, setBackgroundColor, setBorder, setBorder, setBorderColor, setBorderRadius, setBorderWidth, setBoxShadow, setCursor, setFixedSize, setFocusListener, setFocusListener, setFocusListener, setFocusListener, setGradient, setHeight, setHeight, setHoverColor, setImage, setImageMode, setMargin, setMargin, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setMouseListener, setMouseListener, setMouseListener, setMouseListener, setOpacity, setOpacity, setPadding, setPadding, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRight, setPaddingTop, setPercentageAnchor, setPercentageAnchors, setPixelAnchor, setPixelAnchors, setPosition, setPressedColor, setResizeListener, setResizeListener, setResizeListener, setResizeListener, setSize, setVisibility, setVisible, setWidth, setWidth, setX, setY, setZ, stopPropagation, unfocuspublic MenuItem()
public MenuItem(java.lang.String text)
public MenuItem(java.lang.String text,
java.lang.String selectCallback)
text - textselectCallback - method name of callback for select eventpublic MenuItem(java.lang.String text,
Control.Predicate selectCallback)
text - textselectCallback - lambda callback for select eventpublic MenuItem(java.lang.String text,
java.lang.String selectCallback,
Shortcut shortcut)
MenuItem(String, String), but also provide a shortcut. The shortcut is
displayed on the menu item and when this shortcut is hit on the keyboard, the callback is
executed as if the menu item had been pressed.text - textselectCallback - method name of callback for select eventshortcut - shortcutpublic MenuItem(java.lang.String text,
Control.Predicate selectCallback,
Shortcut shortcut)
#MenuItem(String, Predicate), but also provide a shortcut. The shortcut is
displayed on the menu item and when this shortcut is hit on the keyboard, the callback is
executed as if the menu item had been pressed.text - textselectCallback - lambda callback for select eventshortcut - shortcutpublic MenuItem(java.lang.String text,
java.lang.String methodName,
Shortcut shortcut,
boolean strong)
text - textmethodName - method nameshortcut - shortcutstrong - strong propertypublic void close()
public void add(MenuItem... items)
items - newItemspublic void add(java.lang.String... strings)
MenuSeparator.strings - arbitrary number of text.public void insert(int position,
MenuItem... items)
position - positionitems - arbitrary number of itemspublic void clear()
public void remove(int index)
index - index of item to removepublic void remove(Control item)
item - item to removepublic Control[] getItems()
public MenuItem getItem(int index)
index - index of item to getpublic int getNumItems()
public void setShortcut(Shortcut shortcut)
shortcut - shortcutpublic Shortcut getShortcut()
public void setChecked(boolean checked)
checked - checkedpublic boolean isChecked()
public void setEnabled(boolean enabled)
ControlsetEnabled in class Controlenabled - enabled statepublic void setSelectListener(java.lang.String methodName,
java.lang.Object target)
MenuItem()methodName - method nametarget - targetpublic void setSelectListener(java.lang.String methodName)
public void setSelectListener(Control.Predicate1<MenuItem> lambda)
MenuItem()lambda - lambda expression with MenuItem() parameterpublic void setSelectListener(Control.Predicate lambda)
lambda - lambda expressionpublic void removeSelectListener()
public void setChildSelectListener(java.lang.String methodName,
java.lang.Object target)
MenuItem()methodName - method nametarget - targetpublic void setChildSelectListener(java.lang.String methodName)
public void setChildSelectListener(Control.Predicate1<MenuItem> lambda)
MenuItem()lambda - lambda expression with MenuItem() parameterpublic void setChildSelectListener(Control.Predicate lambda)
lambda - lambda expressionpublic void removeChildSelectListener()
public static void parseMenu(java.lang.String menuString,
MenuBar menubar)
"<>" and start with their text, followed by an optional ":" after which the
callback method comes. Finally a shortcut can be specified by starting with "-". The
MenuParser is still a bit experimental, but seems to work so far.
Examples:
"<File <New><Open><Recent <File 1><File 2><File3>><Save><Save As>> <Edit<Undo><Redo>>"
"<File <New -Ctrl+N><Open -Ctrl+O><Recent <File 1><File 2><File3>><Save -Ctrl-S><Save As -Ctrl-Shift-S>> <Edit<Undo -Control-Z><Redo -CONTROL+Y>>"
"<File <New:newFile -Ctrl+N><Open:openFile -Ctrl+O><Recent <File 1><File 2><File3>><Save -Ctrl-S><Save As -Ctrl-Shift-S>> <Edit<Undo:undo -Control-Z><Redo:redo -CONTROL+Y>>"
newFile() openFile() etc. have been declared)
Shortcuts can also be given without giving a callback method and the other way round.
The instruction sequences for starting the callback/shortcut details can be set by calling
parseMenu(String, MenuBar, String, String) or
parseMenu(String, ContextMenu, String, String).menuString - string container menu coding informationmenubar - the menu bar that the menus should be added topublic static void parseMenu(java.lang.String menuString,
MenuBar menubar,
java.lang.String shortcutIntroduceSequence,
java.lang.String callbackIntroduceSequence)
public static void parseMenu(java.lang.String menuString,
ContextMenu contextMenu)
parseMenu(String, MenuBar) but for context menus.menuString - string container menu coding informationcontextMenu - the context menu that the menus should be added toparseMenu(String, MenuBar)public static void parseMenu(java.lang.String menuString,
ContextMenu contextMenu,
java.lang.String shortcutIntroduceSequence,
java.lang.String callbackIntroduceSequence)
Processing Library guiSET by Mc Zen. (c) 2021