Interface Focusable<S extends Focusable<S>>
- Type Parameters:
S- the component's own type, which the setters return
- All Superinterfaces:
EventTarget<S>
- All Known Subinterfaces:
Button, CalendarView, CheckBox, ColorPicker, ComboBox<T>, CycleButton<T>, DatePicker, DateTimePicker, DropDownButton, Expander, Flyout, GridView<T>, ListView<T>, Menu, NavigationView, PasswordTextBox, RadioButton, ScrollBar, ScrollPanel, Slider, Spinner, SplitPane, TabBar, TableView<T>, TextArea, TextBox, TimePicker, ToggleButton, ToggleSwitch, TreeView<T>
A component that can take keyboard focus and be reached with Tab, such as a button, a text box or a list.
Keyboard input goes to the focused component and bubbles up from it, so containers hear
InputEvents.KEY without being focusable themselves. Components that
do not implement this interface never take focus.
A component that implements it starts out focusable and tabbable, with tab index 0. To make a custom component
focusable, extend CustomComponent and declare
implements Focusable<Self>: the class already has every method below. Do not implement this interface any
other way.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EventType<FocusEvent> Told after the component gained keyboard focus.static final EventType<FocusEvent> Told after the component lost keyboard focus. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the component can take keyboard focus now.booleanReturns whether this component has keyboard focus.booleanReturns whether this component has keyboard focus that should be shown, as a focus ring or a lit face.booleanReturns whether Tab and Shift+Tab stop at this component.booleanAsks the host to give this component keyboard focus.setFocusable(boolean focusable) Sets whether the component can take keyboard focus, by a click or byrequestFocus().setTabbable(boolean tabbable) Sets whether Tab and Shift+Tab stop at this component.setTabIndex(int tabIndex) Sets the tab index.inttabIndex()Returns the tab index.Methods inherited from interface EventTarget
onEvent, onEvent, subscribe
-
Field Details
-
FOCUS_GAINED
Told after the component gained keyboard focus. Direct. Default behavior: a text box moves its caret to the end. -
FOCUS_LOST
Told after the component lost keyboard focus. Direct.
-
-
Method Details
-
isFocusable
boolean isFocusable()Returns whether the component can take keyboard focus now.- Returns:
- true unless turned off with
setFocusable(false)
-
setFocusable
Sets whether the component can take keyboard focus, by a click or byrequestFocus(). Turning it off suits parts of a control that should leave focus where it is, such as the list in a combo box's popup. Turning it off on the focused component clears focus at once, and the component hearsFOCUS_LOST.- Parameters:
focusable- false to refuse focus- Returns:
- this component
-
isTabbable
boolean isTabbable()Returns whether Tab and Shift+Tab stop at this component.- Returns:
- true unless turned off with
setTabbable(false)
-
setTabbable
Sets whether Tab and Shift+Tab stop at this component. Only matters while it is focusable.- Parameters:
tabbable- false to leave the component out of tab order- Returns:
- this component
-
tabIndex
int tabIndex()Returns the tab index.- Returns:
- the tab index; 0 by default
-
setTabIndex
Sets the tab index. Tab visits components in ascending tab index, and components with equal indexes in tree order (depth first, children in the order they were added). Negative values are allowed.- Parameters:
tabIndex- the tab index- Returns:
- this component
-
isFocused
boolean isFocused()Returns whether this component has keyboard focus. At most one component per host has focus.- Returns:
- true while focused
-
isFocusVisible
boolean isFocusVisible()Returns whether this component has keyboard focus that should be shown, as a focus ring or a lit face. Focus is shown when it came from the keyboard, or from code while the last press was a key's rather than a pointer's, and also once a key is pressed while it has focus; a pointer press hides it again. So a button clicked with the mouse keeps focus without looking focused, and Tab shows where focus is. When the host becomes active again, focus comes back shown as it was. Strata's controls draw their focus rings, lit faces and keyboard cursors only while this is true, and text boxes show their focused look whenever they have focus. Themes can style it through thefocus_visiblestyle state.- Returns:
- true while focused and focus is shown
-
requestFocus
boolean requestFocus()Asks the host to give this component keyboard focus. Fails, changing nothing, unless the component is attached, focusable, visible and enabled, with every ancestor visible and enabled. While a dialog is open, it also fails for a component below the top dialog, so only the dialog's content and overlays opened above it can take focus.- Returns:
- true if the component now has focus
-