Display sketch code: MenuDemo.pde. The code for Menu is in Clickable.pde
Menus are in many respects similar to ComboBoxes except that Menus appear in a MenuBar at the top of the sketch and do not have a drop down arrow button. Constructor 1 and constructor 2 are similar to the first constructor for a ComboBox in that they are given a list of labels for the buttons in the pull down list. They are almost the same except constructor 2 allows setting the width of the drop down list separately from the menu button. Constructor 3 is similar to the second ComboBox constructor in that it allows one to supply buttons for the pull down list.
In this demo, constructors 1 and 2 allow the user to pick a color. The third constructor allows the user to use check boxes as a sort of color mixer.
The field h specifies the width of the Menu's permanent button in the menubar. Fields x, y, and h are set automatically.
class Menu
extends ComboBox
which extends Clickable
Menu items are placed on the top of sketch on the MenuBar. The MenuBar must be created before the Menu item because it supplies color and location information to the Menu item during its construction. A Menu differs from a ComboBox only by its construction. It doesn't have a "down arrow". It will not scroll. While it keeps track of a selected item like a Combo box, the label of the selected item is never copied to the permanent button in the MenuBar, and by default, does not have any selected colors to indicate a button as being selected.
The Menu class extends ComboBox and uses the same methods which are able to distinguish between ComboBoxes and Menus because "comboArrow" is null for Menus and setPermanentLabel(...) is used.
** Menu(int theWidth, String label, String[] labels,
MenuBar theMenuBar) - This constructor is similar to the first ComboBox constructor in that it is given a list of labels that are used to created the pull down button list. It creates a menu with a permanent button displayed in the MenuBar with a list of menu buttons (which are normally hidden) that are created from the labels array. "label" is displayed in the button in the MenuBar. "theWidth" determines the width of the MenuBar button and pull down list. |
** Menu(int theWidth, String label,
int listWidth, String[] labels, MenuBar theMenuBar, boolean ignore) - This constructor is similar to the first Menu constructor in that it is given a list of labels that are used to created the pull down button list. However, it allows different width to be specified for the button in the MenuBar and for the pull down list. It creates a menu with a permanent button displayed in the MenuBar with a list of menu buttons (which are normally hidden) that are created from the labels array. "label" is displayed in the button in the MenuBar. "theWidth" determines the width of the MenuBar button while "listWidth" specifies the width of the pull down list. "ignore" is included only because of "bug" in Processing.js and is (as one would expect) ignored. |
** Menu(int theWidth, int panelHeight, String label, ButtonGroup aBtnGrp, MenuBar theMenuBar) - This constructor is similar to the second ComboBox constructor in that it is given an array of buttons to be used in the pull down list. It creates a menu with a permanent button displayed in the MenuBar. "label" is displayed in the button in the MenuBar. "theWidth" determines the width of the MenuBar button and the optional panel. "panelHeight" is the height of an optional panel that is placed behind the buttons in the pull down list. The panel is not drawn if "panelHeight" is 0. Important note: The location given in the buttons in the ButtonGroup is relative to the location of the menu button in the MenuBar. Normally all the buttons should be given x location 0. The y location of the first button should be 0. The y location of additional buttons should be the y location of the previous button plus the height of the previous button. |
Method use codes:
** This constructor or method is designed to be called in the user sketch.
* This method is normally not called in the user's sketch unless the Clickable item was not been included in a ClickableGroup. ClickableGroup automatically uses the method as needed. Exception: This method may be needed if the user is extending Clickable with a new class.
# This constructor or method is rarely used in the user program. In Java, it would probably marked "private". Clickable, ScrollBar, and some other abstract constructors would never be called directly by the user sketch because they do nothing useful unless the user is extending a class.
Inherited from ComboBox
Fields
WIDTH_DOWN_ARROW,
ITEM_HEIGHT,
comboListArray ,
comboButton,
comboArrow,
comboListBox,
c, overC,
listBoxVisible,
pnlHeight,
showSelectedLabel
Constructors
ComboBox, ComboBox, ComboBox
Methods
checkForClick,
display,
getClickedItemNum,
getGroupLength,
getItem,
getSelectedItem,
getSelectedItemNum,
getSelectedLabel,
hasBeenClicked,
hideSomething,
isOver,
setEnabled,
setLabel,
setPermanentLabel,
setScrollable,
setSelectedItemNum,
setVisible,
toString
Inherited from Clickable
Fields
NOTHING_CLICKED,
COMBO_BUTTON,
DISABLED_COLOR,
borderColor,
c,
clicked,
clickedItemNum,
colorState,
enabled,
h,
label,
over,
overC,
scrollable,
selected,
selectedItemNum,
visible,
w,
x,
y
Constructors
Clickable
Methods
checkForClick,
display,
doNotSelect,
getClickedItemNum,
getColorState,
getH,
getItem,
getLabel,
getSelected,
getSelectedItem,
getSelectedItemLabel,
getSelectedItemNum,
getW,
getX,
getY,
hasBeenClicked,
hideSomething,
isOver,
setBorderColor,
setColorState,
setH,
setLabel,
setScrollable,
setSelected,
setSelectedItemNum,
setEnabled,
setVisible,
setW,
setX,
setY,
sX,
sY
Revised: 04/11/2014