V
- Type to use for the items in the combo boxComponent
, Interactable
, TextGUIElement
public class ComboBox<V> extends AbstractInteractableComponent<ComboBox<V>>
TextBox
.Modifier and Type | Class | Description |
---|---|---|
static class |
ComboBox.ComboBoxRenderer<V> |
Helper interface that doesn't add any new methods but makes coding new combo box renderers a little bit more clear
|
static class |
ComboBox.DefaultComboBoxRenderer<V> |
This class is the default renderer implementation which will be used unless overridden.
|
static interface |
ComboBox.Listener |
Listener interface that can be used to catch user events on the combo box
|
Interactable.FocusChangeDirection, Interactable.Result
Constructor | Description |
---|---|
ComboBox(String initialText,
Collection<V> items) |
Creates a new
ComboBox initialized with N number of items supplied through the items parameter. |
ComboBox(Collection<V> items) |
Creates a new
ComboBox initialized with N number of items supplied through the items parameter. |
ComboBox(Collection<V> items,
int selectedIndex) |
Creates a new
ComboBox initialized with N number of items supplied through the items parameter. |
ComboBox(V... items) |
Creates a new
ComboBox initialized with N number of items supplied through the varargs parameter. |
Modifier and Type | Method | Description |
---|---|---|
ComboBox<V> |
addItem(int index,
V item) |
Adds a new item to the combo box, at a specific index
|
ComboBox<V> |
addItem(V item) |
Adds a new item to the combo box, at the end
|
ComboBox<V> |
addListener(ComboBox.Listener listener) |
Adds a new listener to the
ComboBox that will be called on certain user actions |
protected void |
afterEnterFocus(Interactable.FocusChangeDirection direction,
Interactable previouslyInFocus) |
Called by
AbstractInteractableComponent automatically after this component has received input focus. |
protected void |
afterLeaveFocus(Interactable.FocusChangeDirection direction,
Interactable nextInFocus) |
Called by
AbstractInteractableComponent automatically after this component has lost input focus. |
ComboBox<V> |
clearItems() |
Removes all items from the combo box
|
protected InteractableRenderer<ComboBox<V>> |
createDefaultRenderer() |
When you create a custom component, you need to implement this method and return a Renderer which is responsible
for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).
|
int |
getDropDownNumberOfRows() |
Returns the number of items to display in drop down at one time, if there are more items in the model there will
be a scrollbar to help the user navigate.
|
V |
getItem(int index) |
Returns the item at the specific index
|
int |
getItemCount() |
Counts and returns the number of items in this combo box
|
int |
getSelectedIndex() |
Returns the index of the currently selected item or -1 for no selection
|
V |
getSelectedItem() |
Returns the item at the selected index, this is the same as calling:
|
String |
getText() |
Returns the text currently displayed in the combo box, this will likely be the label of the selected item but for
writable combo boxes it's also what the user has typed in
|
int |
getTextInputPosition() |
For writable combo boxes, this method returns the position where the text input cursor is right now.
|
Interactable.Result |
handleKeyStroke(KeyStroke keyStroke) |
This method can be overridden to handle various user input (mostly from the keyboard) when this component is in
focus.
|
boolean |
isDropDownFocused() |
Returns
true if the users input focus is currently on the drop-down button of the combo box, so that
pressing enter would trigger the popup window. |
boolean |
isReadOnly() |
Returns
true if this combo box is in read-only mode |
ComboBox<V> |
remoteItem(int index) |
Removes an item from the combo box at a particular index
|
ComboBox<V> |
removeItem(V item) |
Removes a particular item from the combo box, if it is present, otherwise does nothing
|
ComboBox<V> |
removeListener(ComboBox.Listener listener) |
Removes a listener from this
ComboBox so that if it had been added earlier, it will no longer be
called on user actions |
void |
setDropDownNumberOfRows(int dropDownNumberOfRows) |
Sets the number of items to display in drop down at one time, if there are more items in the model there will
be a scrollbar to help the user navigate.
|
ComboBox<V> |
setItem(int index,
V item) |
Updates the combo box so the item at the specified index is swapped out with the supplied value in the
item parameter |
ComboBox<V> |
setReadOnly(boolean readOnly) |
Sets the combo box to either read-only or writable.
|
void |
setSelectedIndex(int selectedIndex) |
Programmatically selects one item in the combo box, which causes the displayed text to change to match the label
of the selected index.
|
void |
setSelectedItem(V item) |
Programmatically selects one item in the combo box by passing in the value the should be selected.
|
addTo, calculatePreferredSize, draw, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, toBasePane, toGlobal, withBorder
getCursorLocation, getInputFilter, getRenderer, handleInput, isEnabled, isFocusable, isFocused, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocus
addTo, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, toBasePane, toGlobal, withBorder
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
draw, isInvalid
public ComboBox(V... items)
ComboBox
initialized with N number of items supplied through the varargs parameter. If at
least one item is given, the first one in the array will be initially selected. By default 10 items will be
displayed at once, more than that and there will be a scroll bar.items
- Items to populate the new combo box withpublic ComboBox(Collection<V> items)
ComboBox
initialized with N number of items supplied through the items parameter. If at
least one item is given, the first one in the collection will be initially selected. By default 10 items will be
displayed at once, more than that and there will be a scroll bar.items
- Items to populate the new combo box withpublic ComboBox(String initialText, Collection<V> items)
ComboBox
initialized with N number of items supplied through the items parameter. The
initial text in the combo box is set to a specific value passed in through the initialText
parameter, it
can be a text which is not contained within the items and the selection state of the combo box will be
"no selection" (so getSelectedIndex()
will return -1) until the user interacts with the combo box and
manually changes it. By default 10 items will be displayed at once, more than that and there will be a scroll bar.initialText
- Text to put in the combo box initiallyitems
- Items to populate the new combo box withpublic ComboBox(Collection<V> items, int selectedIndex)
ComboBox
initialized with N number of items supplied through the items parameter. The
initially selected item is specified through the selectedIndex
parameter. By default 10 items will be
displayed at once, more than that and there will be a scroll bar.items
- Items to populate the new combo box withselectedIndex
- Index of the item which should be initially selectedpublic ComboBox<V> addItem(V item)
item
- Item to add to the combo boxpublic ComboBox<V> addItem(int index, V item)
index
- Index to add the item atitem
- Item to addpublic ComboBox<V> removeItem(V item)
item
- Item to remove from the combo boxpublic ComboBox<V> remoteItem(int index)
index
- Index of the item to removeIndexOutOfBoundsException
- if the index is out of rangepublic ComboBox<V> setItem(int index, V item)
item
parameterindex
- Index of the item to swap outitem
- Item to replace withpublic int getItemCount()
public V getItem(int index)
index
- Index of the item to returnIndexOutOfBoundsException
- if the index is out of rangepublic String getText()
public ComboBox<V> setReadOnly(boolean readOnly)
readOnly
- If the combo box should be in read-only mode, pass in true
, otherwise false
for
writable modepublic boolean isReadOnly()
true
if this combo box is in read-only modetrue
if this combo box is in read-only mode, false
otherwisepublic boolean isDropDownFocused()
true
if the users input focus is currently on the drop-down button of the combo box, so that
pressing enter would trigger the popup window. This is generally used by renderers only and is always true for
read-only combo boxes as the component won't allow you to focus on the text in that mode.true
if the input focus is on the drop-down "button" of the combo boxpublic int getTextInputPosition()
public int getDropDownNumberOfRows()
public void setDropDownNumberOfRows(int dropDownNumberOfRows)
dropDownNumberOfRows
- Max number of items (rows) to display at one time in the combo boxpublic void setSelectedIndex(int selectedIndex)
selectedIndex
- Index of the item to select, or -1 if the selection should be clearedIndexOutOfBoundsException
- if the index is out of rangepublic void setSelectedItem(V item)
toString()
method of item
.
If called with null
, the selection is cleared.
item
- Item in the combo box to select, or null if the selection should be clearedpublic int getSelectedIndex()
public V getSelectedItem()
getSelectedIndex() > -1 ? getItem(getSelectedIndex()) : null
public ComboBox<V> addListener(ComboBox.Listener listener)
ComboBox
that will be called on certain user actionslistener
- Listener to attach to this ComboBox
public ComboBox<V> removeListener(ComboBox.Listener listener)
ComboBox
so that if it had been added earlier, it will no longer be
called on user actionslistener
- Listener to remove from this ComboBox
protected void afterEnterFocus(Interactable.FocusChangeDirection direction, Interactable previouslyInFocus)
AbstractInteractableComponent
AbstractInteractableComponent
automatically after this component has received input focus. You
can override this method if you need to trigger some action based on this.afterEnterFocus
in class AbstractInteractableComponent<ComboBox<V>>
direction
- How focus was transferred, keep in mind this is from the previous component's point of view so
if this parameter has value DOWN, focus came in from abovepreviouslyInFocus
- Which interactable component had focus previouslyprotected void afterLeaveFocus(Interactable.FocusChangeDirection direction, Interactable nextInFocus)
AbstractInteractableComponent
AbstractInteractableComponent
automatically after this component has lost input focus. You
can override this method if you need to trigger some action based on this.afterLeaveFocus
in class AbstractInteractableComponent<ComboBox<V>>
direction
- How focus was transferred, keep in mind this is from the this component's point of view so
if this parameter has value DOWN, focus is moving down to a component belownextInFocus
- Which interactable component is going to receive focusprotected InteractableRenderer<ComboBox<V>> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractInteractableComponent<ComboBox<V>>
public Interactable.Result handleKeyStroke(KeyStroke keyStroke)
AbstractInteractableComponent
handleInput(..)
is final in
AbstractInteractableComponent
to ensure the input filter is properly handled. If the filter decides that
this event should be processed, it will call this method.handleKeyStroke
in class AbstractInteractableComponent<ComboBox<V>>
keyStroke
- What input was entered by the userCopyright © 2020. All rights reserved.