Interface ComponentBuilder<T,C extends JComponent,B extends ComponentBuilder<T,C,B>>

Type Parameters:
T - the type of the value the component represents
C - the component type
B - 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 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 Details

    • COMPONENT_VALUE

      static final String COMPONENT_VALUE
      The client property key for the associated ComponentValue
       
         JTextField textField =
                  Components.stringField()
                          .build();
      
         ComponentValue<String, JTextField> componentValue =
                  (ComponentValue<String, JTextField>)
                          textField.getClientProperty(COMPONENT_VALUE);
       
       
      See Also:
    • TRANSFER_FOCUS_ON_ENTER

      static final PropertyValue<Boolean> 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

      B label(JLabel label)
      Parameters:
      label - the label for the component
      Returns:
      this builder instance
      See Also:
    • focusable

      B focusable(boolean focusable)
      Parameters:
      focusable - false if the component should not be focusable
      Returns:
      this builder instance
      See Also:
    • preferredHeight

      B preferredHeight(int preferredHeight)
      Parameters:
      preferredHeight - the preferred component height
      Returns:
      this builder instance
    • preferredWidth

      B preferredWidth(int preferredWidth)
      Parameters:
      preferredWidth - the preferred component width
      Returns:
      this builder instance
    • preferredSize

      B preferredSize(Dimension preferredSize)
      Parameters:
      preferredSize - the preferred component size
      Returns:
      this builder instance
      See Also:
    • maximumHeight

      B maximumHeight(int maximumHeight)
      Parameters:
      maximumHeight - the maximum component height
      Returns:
      this builder instance
    • maximumWidth

      B maximumWidth(int maximumWidth)
      Parameters:
      maximumWidth - the maximum component width
      Returns:
      this builder instance
    • maximumSize

      B maximumSize(Dimension maximumSize)
      Parameters:
      maximumSize - the maximum component size
      Returns:
      this builder instance
      See Also:
    • minimumHeight

      B minimumHeight(int minimumHeight)
      Parameters:
      minimumHeight - the minimum component height
      Returns:
      this builder instance
    • minimumWidth

      B minimumWidth(int minimumWidth)
      Parameters:
      minimumWidth - the minimum component width
      Returns:
      this builder instance
    • minimumSize

      B minimumSize(Dimension minimumSize)
      Parameters:
      minimumSize - the minimum component size
      Returns:
      this builder instance
      See Also:
    • border

      B border(Border border)
      Parameters:
      border - the component border
      Returns:
      this builder instance
      See Also:
    • transferFocusOnEnter

      B transferFocusOnEnter(boolean 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

      B toolTipText(String toolTipText)
      Parameters:
      toolTipText - the tool tip text
      Returns:
      this builder instance
      See Also:
    • enabled

      B enabled(boolean enabled)
      Sets the enabled state of the component, for a dynamic enabled state use enabled(StateObserver). Overridden by enabled(StateObserver).
      Parameters:
      enabled - the enabled state
      Returns:
      this builder instance
      See Also:
    • enabled

      B enabled(StateObserver enabled)
      Parameters:
      enabled - the state observer controlling the component enabled status
      Returns:
      this builder instance
    • popupMenuControl

      B popupMenuControl(Function<C,Control> popupMenuControl)
      Parameters:
      popupMenuControl - a function, receiving the component being built, providing the control to base a popup menu on
      Returns:
      this builder instance
    • popupMenuControls

      B popupMenuControls(Function<C,Controls> popupMenuControls)
      Parameters:
      popupMenuControls - a function, receiving the component being built, providing the controls to base a popup menu on
      Returns:
      this builder instance
    • popupMenu

      B popupMenu(Function<C,JPopupMenu> popupMenu)
      Parameters:
      popupMenu - a function, receiving the component being built, providing the popup menu
      Returns:
      this builder instance
      See Also:
    • font

      B font(Font font)
      Parameters:
      font - the component font
      Returns:
      this builder instance
      See Also:
    • foreground

      B foreground(Color foreground)
      Parameters:
      foreground - the foreground color
      Returns:
      this builder instance
      See Also:
    • background

      B background(Color background)
      Parameters:
      background - the background color
      Returns:
      this builder instance
      See Also:
    • opaque

      B opaque(boolean opaque)
      Parameters:
      opaque - true if the component should be opaque
      Returns:
      this builder instance
      See Also:
    • visible

      B visible(boolean visible)
      Parameters:
      visible - the initial component visibility, default true
      Returns:
      this builder instance
      See Also:
    • componentOrientation

      B componentOrientation(ComponentOrientation orientation)
      Parameters:
      orientation - the component orientation
      Returns:
      this builder instance
      See Also:
    • validator

      B validator(Value.Validator<T> validator)
      Parameters:
      validator - the validator to use
      Returns:
      this builder instance
    • keyEvent

      B keyEvent(KeyEvents.Builder keyEventBuilder)
      Enables the key event defined by the given KeyEvents.Builder on the component. Note that setting transferFocusOnEnter(boolean) to true overrides any conflicting key event based on KeyEvent.VK_ENTER added via this method.
      Parameters:
      keyEventBuilder - a key event builder to enable on the component
      Returns:
      this builder instance
    • clientProperty

      B clientProperty(Object key, Object value)
      Adds an arbitrary key/value "client property" to the component
      Parameters:
      key - the key
      value - the value
      Returns:
      this builder instance
      See Also:
    • focusListener

      B focusListener(FocusListener focusListener)
      Parameters:
      focusListener - the focus listener
      Returns:
      this builder instance
      See Also:
    • mouseListener

      B mouseListener(MouseListener mouseListener)
      Parameters:
      mouseListener - the mouse listener
      Returns:
      this builder instance
      See Also:
    • mouseMotionListener

      B mouseMotionListener(MouseMotionListener mouseMotionListener)
      Parameters:
      mouseMotionListener - the mouse motion listener
      Returns:
      this builder instance
      See Also:
    • mouseWheelListener

      B mouseWheelListener(MouseWheelListener mouseWheelListener)
      Parameters:
      mouseWheelListener - the mouse wheel listener
      Returns:
      this builder instance
      See Also:
    • keyListener

      B keyListener(KeyListener keyListener)
      Parameters:
      keyListener - the key listener
      Returns:
      this builder instance
      See Also:
    • componentListener

      B componentListener(ComponentListener componentListener)
      Parameters:
      componentListener - the component listener
      Returns:
      this builder instance
      See Also:
    • propertyChangeListener

      B propertyChangeListener(PropertyChangeListener propertyChangeListener)
      Parameters:
      propertyChangeListener - the property change listener
      Returns:
      this builder instance
      See Also:
    • propertyChangeListener

      B propertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
      Parameters:
      propertyName - the name of the property to listen for
      propertyChangeListener - the property change listener
      Returns:
      this builder instance
      See Also:
    • transferHandler

      B transferHandler(TransferHandler transferHandler)
      Parameters:
      transferHandler - the transfer handler
      Returns:
      this builder instance
      See Also:
    • focusCycleRoot

      B focusCycleRoot(boolean focusCycleRoot)
      Parameters:
      focusCycleRoot - true if the component should be the root of a focus traversal cycle
      Returns:
      this builder instance
      See Also:
    • onSetVisible

      B onSetVisible(Consumer<C> onSetVisible)
      Parameters:
      onSetVisible - called when the component is made visible for the first time
      Returns:
      this builder instance
    • link

      B link(Value<T> linkedValue)
      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

      B link(ValueObserver<T> linkedValue)
      Creates a read-only link to the given ValueObserver.
      Parameters:
      linkedValue - a value to link to the component value
      Returns:
      this builder instance
    • listener

      B listener(Runnable listener)
      Parameters:
      listener - a listener to add to the resulting component value
      Returns:
      this builder instance
    • consumer

      B consumer(Consumer<T> consumer)
      Parameters:
      consumer - a consumer to add to the resulting component value
      Returns:
      this builder instance
    • value

      B value(T value)
      Sets the initial value for the component, unless value(s) have been linked via link(Value) or link(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

      B onBuild(Consumer<C> onBuild)
      Parameters:
      onBuild - called when the component has been built.
      Returns:
      this builder instance
    • onBuildValue

      B onBuildValue(Consumer<ComponentValue<T,C>> 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

      C build(Consumer<C> onBuild)
      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

      ComponentValue<T,C> buildValue(Consumer<ComponentValue<T,C>> onBuild)
      Builds and returns the component value.
      Parameters:
      onBuild - called after the component value is built.
      Returns:
      the component value