Package swingtree

Class UIForTabbedPane<P extends JTabbedPane>

Type Parameters:
P - The type of the JTabbedPane instance that this builder node configures.

public final class UIForTabbedPane<P extends JTabbedPane> extends UIForAnySwing<UIForTabbedPane<P>,P>
A SwingTree builder node designed for configuring JTabbedPane instances.
  • Method Details

    • _state

      protected swingtree.BuilderState<P> _state()
      Description copied from class: UIForAnything
      Returns the state of the builder, which is a container for the wrapped component as well as it's type and current EventProcessor.
      Specified by:
      _state in class UIForAnything<UIForTabbedPane<P extends JTabbedPane>,P extends JTabbedPane,JComponent>
      Returns:
      The state of the builder.
    • _newBuilderWithState

      protected UIForTabbedPane<P> _newBuilderWithState(swingtree.BuilderState<P> newState)
      Description copied from class: UIForAnything
      An internal wither method which creates a new builder instance with the provided BuilderState stored inside it.
      Specified by:
      _newBuilderWithState in class UIForAnything<UIForTabbedPane<P extends JTabbedPane>,P extends JTabbedPane,JComponent>
      Parameters:
      newState - The new state which should be stored inside the new builder instance.
      Returns:
      A new builder instance with the provided state stored inside it.
    • onTabMouseClick

      public final UIForTabbedPane<P> onTabMouseClick(sprouts.Action<TabDelegate> onClick)
      Adds an action to be performed when a mouse click is detected on a tab. The action will receive a TabDelegate instance which not only delegates the current tabbed pane and mouse event, but also tells the action which tab was clicked and whether the clicked tab is selected.
      Parameters:
      onClick - The action to be performed when a tab is clicked.
      Returns:
      This builder node.
      Throws:
      NullPointerException - if the given action is null.
    • onTabMousePress

      public final UIForTabbedPane<P> onTabMousePress(sprouts.Action<TabDelegate> onPress)
      Adds an action to be performed when a mouse press is detected on a tab. The action will receive a TabDelegate instance which not only delegates the current tabbed pane and mouse event, but also tells the action which tab was pressed and whether the pressed tab is selected.
      Parameters:
      onPress - The action to be performed when a tab is pressed.
      Returns:
      This builder node.
      Throws:
      NullPointerException - if the given action is null.
    • onTabMouseRelease

      public final UIForTabbedPane<P> onTabMouseRelease(sprouts.Action<TabDelegate> onRelease)
      Adds an action to be performed when a mouse release is detected on a tab. The action will receive a TabDelegate instance which not only delegates the current tabbed pane and mouse event, but also tells the action which tab was released and whether the released tab is selected.
      Parameters:
      onRelease - The action to be performed when a tab is released.
      Returns:
      This builder node.
      Throws:
      NullPointerException - if the given action is null.
    • onTabMouseEnter

      public final UIForTabbedPane<P> onTabMouseEnter(sprouts.Action<TabDelegate> onEnter)
      Adds an action to be performed when a mouse enter is detected on a tab. The action will receive a TabDelegate instance which not only delegates the current tabbed pane and mouse event, but also tells the action which tab was entered and whether the entered tab is selected.
      Parameters:
      onEnter - The action to be performed when a tab is entered.
      Returns:
      This builder node.
      Throws:
      NullPointerException - if the given action is null.
    • onTabMouseExit

      public final UIForTabbedPane<P> onTabMouseExit(sprouts.Action<TabDelegate> onExit)
      Adds an action to be performed when a mouse exit is detected on a tab. The action will receive a TabDelegate instance which not only delegates the current tabbed pane and mouse event, but also tells the action which tab was exited and whether the exited tab is selected.
      Parameters:
      onExit - The action to be performed when a tab is exited.
      Returns:
      This builder node.
      Throws:
      NullPointerException - if the given action is null.
    • withSelectedIndex

      public final UIForTabbedPane<P> withSelectedIndex(int index)
      Sets the selected tab based on the given index.
      Parameters:
      index - The index of the tab to select.
      Returns:
      This builder node.
    • withSelectedIndex

      public final UIForTabbedPane<P> withSelectedIndex(sprouts.Val<Integer> index)
      Dynamically sets the selected tab based on the given index property. So when the index property changes, the selected tab will change accordingly.
      Parameters:
      index - The index property of the tab to select.
      Returns:
      This builder node.
    • withSelectedIndex

      public final UIForTabbedPane<P> withSelectedIndex(sprouts.Var<Integer> index)
      Binds the given index property to the selection index of the tabbed pane, which means that when the index property changes, the selected tab will change accordingly and when the user selects a different tab, the index property will be updated accordingly.
      Parameters:
      index - The index property of the tab to select.
      Returns:
      This builder node.
    • withTabPlacementAt

      public final UIForTabbedPane<P> withTabPlacementAt(UI.Side side)
      Defines the tab placement side based on the given UI.Side enum, which maps directly to the JTabbedPane.setTabPlacement(int) method.
      Parameters:
      side - The position to use for the tabs.
      Returns:
      This builder node.
    • withTabPlacementAt

      public final UIForTabbedPane<P> withTabPlacementAt(sprouts.Val<UI.Side> side)
      Binds the supplied property to the tab placement of the tabbed pane. This means that when the property changes, the tab placement will change accordingly. The UI.Side enum maps directly to the JTabbedPane.setTabPlacement(int) method.
      Parameters:
      side - The position property to use for the tabs.
      Returns:
      This builder node.
    • withOverflowPolicy

      public final UIForTabbedPane<P> withOverflowPolicy(UI.OverflowPolicy policy)
      Defines the overflow policy based on the given UI.OverflowPolicy enum, which maps directly to the JTabbedPane.setTabLayoutPolicy(int) method. The overflow policy must either be UI.OverflowPolicy.SCROLL or UILayoutConstants.WRAP(int). The UI.OverflowPolicy.SCROLL policy will make the tabs scrollable when there are too many tabs to fit in the tabbed pane. The UILayoutConstants.WRAP(int) policy will make the tabs wrap to the next line when there are too many tabs to fit in the tabbed pane.
      Parameters:
      policy - The overflow policy to use for the tabs.
      Returns:
      This builder node.
    • withOverflowPolicy

      public final UIForTabbedPane<P> withOverflowPolicy(sprouts.Val<UI.OverflowPolicy> policy)
      Binds the supplied enum property to the overflow policy of the tabbed pane. When the item of the property changes, the overflow policy will change accordingly. The UI.OverflowPolicy enum maps directly to the JTabbedPane.setTabLayoutPolicy(int) method.
      Parameters:
      policy - The overflow policy property to use for the tabs.
      Returns:
      This builder node.
    • add

      public final UIForTabbedPane<P> add(Tab tab)
      Adds a tab to the tabbed pane based on the given Tab configuration. The tab will be added to the end of the tab list.
      Parameters:
      tab - The tab to add to the tabbed pane.
      Returns:
      This builder node.
      Throws:
      NullPointerException - if the given tab is null.
    • addAll

      public <M> UIForTabbedPane<P> addAll(sprouts.Vals<M> tabModels, TabSupplier<M> tabSupplier)
      Dynamically generates tabs for items in a Vals list and automatically updates them when the items change. The items are typically view model instances, but can be any type.

      The provided TabSupplier lambda is invoked with each item from the list, returning a Tab to be added to the JTabbedPane wrapped by this builder.

      Note: Binding tabs to a Vals list assumes no other tabs are present.

      Usage:

      
           UI.panel()
            .add(
                UI.tabbedPane().addAll(tabs, model ->
                    switch(model.type()) {
                        case LOGIN -> UI.tab("Login").add(..);
                        case ABOUT -> UI.tab("About").add(..);
                        case SETTINGS -> UI.tab("Settings").add(..);
                    }
                )
            )
       
      Type Parameters:
      M - The type of items in the Vals list.
      Parameters:
      tabModels - A list of items, typically view model instances.
      tabSupplier - A lambda to generate a Tab for each item.
      Returns:
      This instance, allowing for builder-style method chaining.
    • addAll

      public <M> UIForTabbedPane<P> addAll(sprouts.Val<sprouts.Tuple<M>> tabModels, TabSupplier<M> tabSupplier)
      Dynamically generates tabs for items in a Tuple Val and automatically updates them when the items change. The tuple items are typically view model instances, but can be any type.

      The provided TabSupplier lambda is invoked with each item from the tuple, returning a Tab to be added to the JTabbedPane wrapped by this builder.

      Note: Binding tabs to a Tuple Val assumes no other tabs are present.

      Usage:

      
           UI.panel()
            .add(
                UI.tabbedPane().addAll(tabs, model ->
                    switch(model.type()) {
                        case LOGIN -> UI.tab("Login").add(..);
                        case ABOUT -> UI.tab("About").add(..);
                        case SETTINGS -> UI.tab("Settings").add(..);
                    }
                )
            )
       
      Type Parameters:
      M - The type of items in the form of a Tuple wrapped by a Val.
      Parameters:
      tabModels - A list of items, typically view model instances.
      tabSupplier - A lambda to generate a Tab for each item.
      Returns:
      This instance, allowing for builder-style method chaining.
    • onChange

      public final UIForTabbedPane<P> onChange(sprouts.Action<ComponentDelegate<P,ChangeEvent>> onChange)
      Adds an Action to the underlying JTabbedPane through an ChangeListener, which will be called when the state of the tabbed pane changes. For more information see JTabbedPane.addChangeListener(javax.swing.event.ChangeListener).
      Parameters:
      onChange - The Action that will be called through the underlying change event.
      Returns:
      This very instance, which enables builder-style method chaining.