Module is.codion.swing.common.ui
Interface ComponentBuilder<T,C extends JComponent,B extends ComponentBuilder<T,C,B>>
- Type Parameters:
T
- the type of the value the component representsC
- the component typeB
- the builder type
- All Known Subinterfaces:
BorderLayoutPanelBuilder
,ButtonBuilder<T,
,C, B> ButtonPanelBuilder
,CheckBoxBuilder
,CheckBoxMenuItemBuilder<B>
,ComboBoxBuilder<T,
,C, B> ControlPanelBuilder<C,
,B> EntityComboBox.Builder
,EntityComboBoxPanel.Builder
,EntitySearchField.Builder
,EntitySearchFieldPanel.Builder
,FileInputPanel.Builder<T>
,FilterTable.Builder<R,
,C> ItemComboBoxBuilder<T>
,ItemSpinnerBuilder<T>
,LabelBuilder<T>
,ListBoxBuilder<T>
,ListBuilder<T,
,V, B> ListBuilder.Items<T>
,ListBuilder.SelectedItem<T>
,ListBuilder.SelectedItems<T>
,ListSpinnerBuilder<T>
,MaskedTextFieldBuilder
,MenuBuilder
,MenuItemBuilder<C,
,B> NumberField.Builder<T>
,NumberSpinnerBuilder<T>
,PanelBuilder
,PasswordFieldBuilder
,ProgressBarBuilder
,RadioButtonBuilder
,RadioButtonMenuItemBuilder<B>
,ScrollPaneBuilder
,SliderBuilder
,SpinnerBuilder<T,
,B> SplitPaneBuilder
,TabbedPaneBuilder
,TemporalField.Builder<T>
,TemporalFieldPanel.Builder<T>
,TextAreaBuilder
,TextComponentBuilder<T,
,C, B> TextFieldBuilder<T,
,C, B> TextFieldPanel.Builder
,ToggleButtonBuilder<C,
,B> ToggleMenuItemBuilder<C,
,B> ToolBarBuilder
- All Known Implementing Classes:
AbstractComponentBuilder
,DefaultComboBoxBuilder
public interface ComponentBuilder<T,C extends JComponent,B extends ComponentBuilder<T,C,B>>
Use
The component is available via
build()
to build a JComponent instance or buildValue()
to build a ComponentValue
instance.The component is available via
ComponentValue.component()
and the associated ComponentValue
instance
is available via the COMPONENT_VALUE
client property.-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The client property key for the associatedComponentValue
static final PropertyValue<Boolean>
Specifies whether focus should be transferred from components on enter.
Note that for JTextArea CTRL is added to move focus forward Value type: Boolean Default value: false -
Method Summary
Modifier and TypeMethodDescriptionbackground
(Color background) build()
Builds a new component instance.Builds a new component instance.Builds and returns the component value.buildValue
(Consumer<ComponentValue<T, C>> onBuild) Builds and returns the component value.clientProperty
(Object key, Object value) Adds an arbitrary key/value "client property" to the componentcomponentListener
(ComponentListener componentListener) componentOrientation
(ComponentOrientation orientation) enabled
(boolean enabled) Sets the enabled state of the component, for a dynamic enabled state useenabled(StateObserver)
.enabled
(StateObserver enabled) focusable
(boolean focusable) focusCycleRoot
(boolean focusCycleRoot) focusListener
(FocusListener focusListener) foreground
(Color foreground) keyEvent
(KeyEvents.Builder keyEventBuilder) Enables the key event defined by the givenKeyEvents.Builder
on the component.keyListener
(KeyListener keyListener) Creates a bidirectional link to the given value.link
(ValueObserver<T> linkedValue) Creates a read-only link to the givenValueObserver
.maximumHeight
(int maximumHeight) maximumSize
(Dimension maximumSize) maximumWidth
(int maximumWidth) minimumHeight
(int minimumHeight) minimumSize
(Dimension minimumSize) minimumWidth
(int minimumWidth) mouseListener
(MouseListener mouseListener) mouseMotionListener
(MouseMotionListener mouseMotionListener) mouseWheelListener
(MouseWheelListener mouseWheelListener) onBuildValue
(Consumer<ComponentValue<T, C>> onBuildValue) onSetVisible
(Consumer<C> onSetVisible) opaque
(boolean opaque) popupMenu
(Function<C, JPopupMenu> popupMenu) popupMenuControl
(Function<C, Control> popupMenuControl) popupMenuControls
(Function<C, Controls> popupMenuControls) preferredHeight
(int preferredHeight) preferredSize
(Dimension preferredSize) preferredWidth
(int preferredWidth) propertyChangeListener
(PropertyChangeListener propertyChangeListener) propertyChangeListener
(String propertyName, PropertyChangeListener propertyChangeListener) toolTipText
(String toolTipText) transferFocusOnEnter
(boolean transferFocusOnEnter) Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwardstransferHandler
(TransferHandler transferHandler) validator
(Value.Validator<T> validator) Sets the initial value for the component, unless value(s) have been linked vialink(Value)
orlink(ValueObserver)
, which then control the inital value.visible
(boolean visible)
-
Field Details
-
COMPONENT_VALUE
The client property key for the associatedComponentValue
JTextField textField = Components.stringField() .build(); ComponentValue<String, JTextField> componentValue = (ComponentValue<String, JTextField>) textField.getClientProperty(COMPONENT_VALUE);
-
TRANSFER_FOCUS_ON_ENTER
Specifies whether focus should be transferred from components on enter.
Note that for JTextArea CTRL is added to move focus forward- Value type: Boolean
- Default value: false
-
-
Method Details
-
label
- Parameters:
label
- the label for the component- Returns:
- this builder instance
- See Also:
-
focusable
- Parameters:
focusable
- false if the component should not be focusable- Returns:
- this builder instance
- See Also:
-
preferredHeight
- Parameters:
preferredHeight
- the preferred component height- Returns:
- this builder instance
-
preferredWidth
- Parameters:
preferredWidth
- the preferred component width- Returns:
- this builder instance
-
preferredSize
- Parameters:
preferredSize
- the preferred component size- Returns:
- this builder instance
- See Also:
-
maximumHeight
- Parameters:
maximumHeight
- the maximum component height- Returns:
- this builder instance
-
maximumWidth
- Parameters:
maximumWidth
- the maximum component width- Returns:
- this builder instance
-
maximumSize
- Parameters:
maximumSize
- the maximum component size- Returns:
- this builder instance
- See Also:
-
minimumHeight
- Parameters:
minimumHeight
- the minimum component height- Returns:
- this builder instance
-
minimumWidth
- Parameters:
minimumWidth
- the minimum component width- Returns:
- this builder instance
-
minimumSize
- Parameters:
minimumSize
- the minimum component size- Returns:
- this builder instance
- See Also:
-
border
- Parameters:
border
- the component border- Returns:
- this builder instance
- See Also:
-
transferFocusOnEnter
Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwards- Parameters:
transferFocusOnEnter
- if true then the text field transfer focus on enter (shift-enter for backwards)- Returns:
- this builder instance
- See Also:
-
toolTipText
- Parameters:
toolTipText
- the tool tip text- Returns:
- this builder instance
- See Also:
-
enabled
Sets the enabled state of the component, for a dynamic enabled state useenabled(StateObserver)
. Overridden byenabled(StateObserver)
.- Parameters:
enabled
- the enabled state- Returns:
- this builder instance
- See Also:
-
enabled
- Parameters:
enabled
- the state observer controlling the component enabled status- Returns:
- this builder instance
-
popupMenuControl
- Parameters:
popupMenuControl
- a function, receiving the component being built, providing the control to base a popup menu on- Returns:
- this builder instance
-
popupMenuControls
- Parameters:
popupMenuControls
- a function, receiving the component being built, providing the controls to base a popup menu on- Returns:
- this builder instance
-
popupMenu
- Parameters:
popupMenu
- a function, receiving the component being built, providing the popup menu- Returns:
- this builder instance
- See Also:
-
font
- Parameters:
font
- the component font- Returns:
- this builder instance
- See Also:
-
foreground
- Parameters:
foreground
- the foreground color- Returns:
- this builder instance
- See Also:
-
background
- Parameters:
background
- the background color- Returns:
- this builder instance
- See Also:
-
opaque
- Parameters:
opaque
- true if the component should be opaque- Returns:
- this builder instance
- See Also:
-
visible
- Parameters:
visible
- the initial component visibility, default true- Returns:
- this builder instance
- See Also:
-
componentOrientation
- Parameters:
orientation
- the component orientation- Returns:
- this builder instance
- See Also:
-
validator
- Parameters:
validator
- the validator to use- Returns:
- this builder instance
-
keyEvent
Enables the key event defined by the givenKeyEvents.Builder
on the component. Note that settingtransferFocusOnEnter(boolean)
to true overrides any conflicting key event based onKeyEvent.VK_ENTER
added via this method.- Parameters:
keyEventBuilder
- a key event builder to enable on the component- Returns:
- this builder instance
-
clientProperty
Adds an arbitrary key/value "client property" to the component- Parameters:
key
- the keyvalue
- the value- Returns:
- this builder instance
- See Also:
-
focusListener
- Parameters:
focusListener
- the focus listener- Returns:
- this builder instance
- See Also:
-
mouseListener
- Parameters:
mouseListener
- the mouse listener- Returns:
- this builder instance
- See Also:
-
mouseMotionListener
- Parameters:
mouseMotionListener
- the mouse motion listener- Returns:
- this builder instance
- See Also:
-
mouseWheelListener
- Parameters:
mouseWheelListener
- the mouse wheel listener- Returns:
- this builder instance
- See Also:
-
keyListener
- Parameters:
keyListener
- the key listener- Returns:
- this builder instance
- See Also:
-
componentListener
- Parameters:
componentListener
- the component listener- Returns:
- this builder instance
- See Also:
-
propertyChangeListener
- Parameters:
propertyChangeListener
- the property change listener- Returns:
- this builder instance
- See Also:
-
propertyChangeListener
- Parameters:
propertyName
- the name of the property to listen forpropertyChangeListener
- the property change listener- Returns:
- this builder instance
- See Also:
-
transferHandler
- Parameters:
transferHandler
- the transfer handler- Returns:
- this builder instance
- See Also:
-
focusCycleRoot
- Parameters:
focusCycleRoot
- true if the component should be the root of a focus traversal cycle- Returns:
- this builder instance
- See Also:
-
onSetVisible
- Parameters:
onSetVisible
- called when the component is made visible for the first time- Returns:
- this builder instance
-
link
Creates a bidirectional link to the given value. Overrides any initial value set.- Parameters:
linkedValue
- a value to link to the component value- Returns:
- this builder instance
-
link
Creates a read-only link to the givenValueObserver
.- Parameters:
linkedValue
- a value to link to the component value- Returns:
- this builder instance
-
listener
- Parameters:
listener
- a listener to add to the resulting component value- Returns:
- this builder instance
-
consumer
- Parameters:
consumer
- a consumer to add to the resulting component value- Returns:
- this builder instance
-
value
Sets the initial value for the component, unless value(s) have been linked vialink(Value)
orlink(ValueObserver)
, which then control the inital value. The initial value is set before any listeners are added, so no events are triggered.- Parameters:
value
- the initial value- Returns:
- this builder instance
-
scrollPane
ScrollPaneBuilder scrollPane()- Returns:
- a
ScrollPaneBuilder
using this component as the view
-
onBuild
- Parameters:
onBuild
- called when the component has been built.- Returns:
- this builder instance
-
onBuildValue
- Parameters:
onBuildValue
- called when the component value has been built.- Returns:
- this builder instance
-
build
C build()Builds a new component instance.- Returns:
- the component
-
build
Builds a new component instance.- Parameters:
onBuild
- called after the component is built.- Returns:
- the component
-
buildValue
ComponentValue<T,C> buildValue()Builds and returns the component value.- Returns:
- the component value
-
buildValue
Builds and returns the component value.- Parameters:
onBuild
- called after the component value is built.- Returns:
- the component value
-