Package swingtree

Class Tab

java.lang.Object
swingtree.Tab

public final class Tab extends Object
An immutable data carrier exposing everything needed to configure a tab of a JTabbedPane. One can create instances of this through the UIFactoryMethods.tab(String) factory method and then add them to instances of a UIForTabbedPane builder like so:

      UI.tabbedPane()
      .add(UI.tab("one").add(UI.panel().add(..)))
      .add(UI.tab("two").withTip("I give info!").add(UI.label("read me")))
      .add(UI.tab("three").withIcon(someIcon).add(UI.button("click me")))
  

Please take a look at the living swing-tree documentation where you can browse a large collection of examples demonstrating how to use the API of this class.

  • Method Summary

    Modifier and Type
    Method
    Description
    final Tab
    add(JComponent contents)
    Use this to add the contents UI to the tab.
    final Tab
    add(UIForAnySwing<?,?> contents)
    Use this to add the contents UI to the tab.
    final Tab
    isEnabledIf(boolean isEnabled)
    A tab may be enabled or disabled, which you can specify with this method.
    final <E extends Enum<E>>
    Tab
    isEnabledIf(E state, sprouts.Var<E> enabledState)
    Binds the boolean enabled state of the tab to a specific enum value and a corresponding enum property.
    final Tab
    isEnabledIf(sprouts.Val<Boolean> isEnabled)
    Binds the boolean property passed to this method to the enabled state of the tab, which means that when the state of the property changes, the enabled state of the tab will change accordingly.
    final Tab
    isSelectedIf(boolean isSelected)
    Use this to make the tab selected by default.
    final <E extends Enum<E>>
    Tab
    isSelectedIf(E state, sprouts.Var<E> selectedState)
    Binds the boolean selection state of the tab to a specific enum value of a corresponding enum property.
    final Tab
    isSelectedIf(sprouts.Val<Boolean> isSelected)
    Binds the boolean property passed to this method to the selected state of the tab, which means that when the state of the property changes, the selected state of the tab will change accordingly.
    final Tab
    isSelectedIf(sprouts.Var<Boolean> isSelected)
    Binds the boolean property passed to this method to the selected state of the tab, which means that when the state of the property changes, the selected state of the tab will change accordingly.
    final Tab
    Use this to register and catch generic MouseListener based mouse click events for this tab.
    final Tab
    Use this to register and catch generic ChangeEvent based selection events for this tab and perform some action when the tab is selected.
    final Tab
    withHeader(JComponent headerComponent)
     
    final Tab
    withHeader(UIForAnySwing<?,?> headerComponent)
    Use this to add custom components to the tab header like buttons, or labels with icons.
    final Tab
    withIcon(Icon icon)
    A tab header may have an icon displayed in it, which you can specify with this method.
    final Tab
    withIcon(sprouts.Val<IconDeclaration> iconDeclaration)
    Allows you to dynamically model the icon displayed on the tab through a property bound to this tab.
    final Tab
    Determines the icon to be displayed in the tab header based on a IconDeclaration, which is essentially just a path to the icon which should be displayed in the tab header.
    final Tab
    Allows you to define the tooltip which should be displayed when hovering over the tab header.
    final Tab
    withTip(sprouts.Val<String> tip)
    Allows you to bind a string property to the tooltip of the tab.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isSelectedIf

      public final Tab isSelectedIf(boolean isSelected)
      Use this to make the tab selected by default.
      Parameters:
      isSelected - The selected state of the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • isSelectedIf

      public final Tab isSelectedIf(sprouts.Var<Boolean> isSelected)
      Binds the boolean property passed to this method to the selected state of the tab, which means that when the state of the property changes, the selected state of the tab will change accordingly. Conversely, when the tab is selected, the property will be set to true, otherwise it will be set to false.
      Parameters:
      isSelected - The selected state property of the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • isSelectedIf

      public final Tab isSelectedIf(sprouts.Val<Boolean> isSelected)
      Binds the boolean property passed to this method to the selected state of the tab, which means that when the state of the property changes, the selected state of the tab will change accordingly. Note that this is not a two-way binding, so when the user changes the selection state of the tab, the property will not be updated.
      Parameters:
      isSelected - The selected state property of the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • isSelectedIf

      public final <E extends Enum<E>> Tab isSelectedIf(E state, sprouts.Var<E> selectedState)
      Binds the boolean selection state of the tab to a specific enum value of a corresponding enum property. When the enum property is set to the provided enum value, the tab will be selected.
      Type Parameters:
      E - The type of the state.
      Parameters:
      state - The state of the tab.
      selectedState - The selected state property of the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • isEnabledIf

      public final Tab isEnabledIf(boolean isEnabled)
      A tab may be enabled or disabled, which you can specify with this method.
      Parameters:
      isEnabled - The enabled state of the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • isEnabledIf

      public final Tab isEnabledIf(sprouts.Val<Boolean> isEnabled)
      Binds the boolean property passed to this method to the enabled state of the tab, which means that when the state of the property changes, the enabled state of the tab will change accordingly.
      Parameters:
      isEnabled - The enabled state property of the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • isEnabledIf

      public final <E extends Enum<E>> Tab isEnabledIf(E state, sprouts.Var<E> enabledState)
      Binds the boolean enabled state of the tab to a specific enum value and a corresponding enum property. When the enum property is set to the provided enum value, the tab will be selected.
      Type Parameters:
      E - The type of the state.
      Parameters:
      state - The state of the tab.
      enabledState - The enabled state property of the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • withIcon

      public final Tab withIcon(Icon icon)
      A tab header may have an icon displayed in it, which you can specify with this method.
      Parameters:
      icon - The icon which should be displayed in the tab header.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • withIcon

      public final Tab withIcon(IconDeclaration icon)
      Determines the icon to be displayed in the tab header based on a IconDeclaration, which is essentially just a path to the icon which should be displayed in the tab header. If the icon resource is not found, then no icon will be displayed.
      Parameters:
      icon - The icon declaration, essentially just a path to the icon which should be displayed in the tab header.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • withIcon

      public final Tab withIcon(sprouts.Val<IconDeclaration> iconDeclaration)
      Allows you to dynamically model the icon displayed on the tab through a property bound to this tab.

      Note that you may not use the Icon or ImageIcon classes directly as a value for your property, instead you must use implementations of the IconDeclaration interface, which merely models the resource location of the icon, but does not load the whole icon itself.

      The reason for this distinction is the fact that traditional Swing icons are heavy objects whose loading may or may not succeed, and so they are not suitable for direct use in a property as part of your view model. Instead, you should use the IconDeclaration interface, which is a lightweight value object that merely models the resource location of the icon even if it is not yet loaded or even does not exist at all.

      This is especially useful in case of unit tests for you view model, where the icon may not be available at all, but you still want to test the behaviour of your view model.

      Parameters:
      iconDeclaration - The icon property which should be displayed in the tab header.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • withTip

      public final Tab withTip(String tip)
      Allows you to define the tooltip which should be displayed when hovering over the tab header.
      Parameters:
      tip - The tooltip which should be displayed when hovering over the tab header.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • withTip

      public final Tab withTip(sprouts.Val<String> tip)
      Allows you to bind a string property to the tooltip of the tab. When the item of the property changes, the tooltip will be updated accordingly. You can see the tooltip when hovering over the tab header.
      Parameters:
      tip - The tooltip property which should be displayed when hovering over the tab header.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • withHeader

      public final Tab withHeader(JComponent headerComponent)
    • withHeader

      public final Tab withHeader(UIForAnySwing<?,?> headerComponent)
      Use this to add custom components to the tab header like buttons, or labels with icons.
      Parameters:
      headerComponent - The component which should be displayed in the tab header.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • add

      public final Tab add(UIForAnySwing<?,?> contents)
      Use this to add the contents UI to the tab.
      Parameters:
      contents - The contents which should be displayed in the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • add

      public final Tab add(JComponent contents)
      Use this to add the contents UI to the tab.
      Parameters:
      contents - The contents which should be displayed in the tab.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • onSelection

      public final Tab onSelection(sprouts.Action<ComponentDelegate<JTabbedPane,ChangeEvent>> onSelected)
      Use this to register and catch generic ChangeEvent based selection events for this tab and perform some action when the tab is selected.
      Parameters:
      onSelected - The action to be executed when the tab is selected.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.
    • onMouseClick

      public final Tab onMouseClick(sprouts.Action<ComponentDelegate<JTabbedPane,MouseEvent>> onClick)
      Use this to register and catch generic MouseListener based mouse click events for this tab. This method adds the provided consumer lambda to the JTabbedPane that this tab is added to.
      Parameters:
      onClick - The lambda instance which will be passed to the JTabbedPane as MouseListener.
      Returns:
      A new Tab instance with the provided argument, which enables builder-style method chaining.