The 1st Constructor ListBox is a traditional ListBox while the other two are nontraditional ListBoxes allowed by this Clickable package.
The first two ListBoxes just let you pick one of four colors. However the third ListBox has checkboxes and serves as a color mixer.
Fields x, y, and w are for location of the top left corner, and the width of the box. h is the height of the optional panel and specifies its height if it is greater than zero. h = 0 means there is no panel. (The optional panel may be useful when nontraditional boxes are created by the third constructor. One was used with the middle ListBox but not in the right hand one.)
Display sketch code: ListBoxDemo.pde. The code for ListBox is in Clickable.pde
class ListBox
extends Clickable
This is basically a ButtonGroup which is displayed as a unit. One of the buttons is selected. The standard display is a set of buttons one above the other. But a ListBox using one of the nontraditional constructors is a great way to create a radio button group! (But see RadioButtonListBox for a standardized radio button group.)
final int ITEM_HEIGHT = 20. Button[] buttonListArray - List of buttons in the ButtonGroup. ButtonGroup buttonListGrp - The ButtonGroup they are in. boolean showSelected - The selected item is shown using the selected color when true. color[] c, overC - Arrays of colors. overC is used when the mouse is over a button. int clickedItemNum - The number (subscript) of the clicked item. color panelColor - Color of panel for nontraditional ListBox. |
** ListBox(int leftX, int topY, int theWidth,
String label, String[] labels, color stdColor, color overColor, color selected, color overSelected) - Constructs a list box. It easiest way to create a ListBox as it automatically creates the ButtonGroup from the list of labels. If it undesirable to show a selected button, then use the standard colors as the selected colors. The first button is assumed to be selected. |
** ListBox (int leftX, int topY, String label,
ButtonGroup btnGrp) - Creates ListBox from supplied ButtonGroup for more flexibility. The first button is assumed to be selected. The locations specified in the buttons are relative to the location of the ListBox. That is, if a button is located at x = 0, it will appear at the left edge of the ListBox. If it is located at y = 0, then it is located at the top of the box. |
** ListBox(int leftX, int topY, int theWidth,
int theHeight, color buttonPanelColor, String label, ButtonGroup btnGrp) - Also creates a list box from the supplied buttons but also adds a panel to hold the buttons. Great for radio buttons made with special circle buttons. The first button is assumed to be selected. The locations specified in the buttons are relative to the location of the ListBox. That is, if a button is located at x = 0, it will appear at the left edge of the ListBox. If it is located at y = 0, then it is located at the top of the box. |
# ListBox(int leftX, int topY, int theWidth,
int theHeight, String label) - This constructor is only used be other constructors!!! This constructor just sets some common parameters. It does not set the ButtonListArray or ButtonListGrp!! So use of it outside of a constructor will cause errors! It sets the location of the upper left corner, the width, the height, the label, clickedItemNum, and selectedItemNum. |
** void setEnabled(boolean b) - Sets the ListBox and all its buttons to enabled or disabled. |
** void setVisible(boolean b) - Sets the ListBox and all its buttons to visible or hidden. |
* void display() - Displays all the buttons in the ListBox assuming it is visible. |
* boolean isOver() - Returns true if the mouse cursor is over any of the buttons in the list. Used in the mouseReleasedMethod (normally automatically by ClickableGroup) and directly by draw() or method called by draw(). |
* boolean checkForClick() - Assuming that the ListBox is visible and enabled, it checks all ListGroup's buttons to see if they have been clicked. If a button has been clicked, it sets setSelectedItemNum and clickedItemNum in addition to setting the clicked field to true. It returns true if any button was clicked. It can only be called (directly or indirectly) in the mouseReleased() method. |
* boolean hasBeenClicked() - Causes the button group to do hasBeenClicked() on its buttons and changes the clicked field to false. Used to determine if any button in the list has been clicked. Used by the draw() method or by a submethod of the draw method. |
** int getClickedItemNum() - Returns the ClickedItemNum. |
** void setSelectedItemNum(int b) - Sets the value of SelectedItemNum and indirectly selects the appropriate button. |
** int getSelectedItemNum() - Returns the selectedItemNum. |
** Button getSelectedItem() - Returns the selected button. |
** String getSelectedLabel() - Returns the label of the selected button. |
** Button getItem(int i) - Returns the specified Button where "i" is the subscript of the button in the strings array and/or the button ListArray. |
** int getGroupLength() - Returns the number of buttons in the ListBox. |
** void setScrollable(boolean canScroll) - Used to specify that this item and all its buttons is or is not scrollable. |
# String toString() - For debugging. Returns a string with lots of information about the ListBox and its ButtonGroup. |
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 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