Class Tab
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 TypeMethodDescriptionfinal Tabadd(JComponent contents) Use this to add the contents UI to the tab.final Tabadd(UIForAnySwing<?, ?> contents) Use this to add the contents UI to the tab.final TabisEnabledIf(boolean isEnabled) A tab may be enabled or disabled, which you can specify with this method.isEnabledIf(E state, sprouts.Val<E> enabledState) Binds the boolean enabled state of the tab to a specific enum value and a corresponding enum property.final TabisEnabledIf(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 TabisSelectedIf(boolean isSelected) Use this to make the tab selected by default.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 TabisSelectedIf(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 TabisSelectedIf(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 TabonMouseClick(sprouts.Action<ComponentDelegate<JTabbedPane, MouseEvent>> onClick) Use this to register and catch genericMouseListenerbased mouse click events for this tab.final TabonSelection(sprouts.Action<ComponentDelegate<JTabbedPane, ChangeEvent>> onSelected) Use this to register and catch genericChangeEventbased selection events for this tab and perform some action when the tab is selected.final TabwithHeader(JComponent headerComponent) final TabwithHeader(UIForAnySwing<?, ?> headerComponent) Use this to add custom components to the tab header like buttons, or labels with icons.final TabA tab header may have an icon displayed in it, which you can specify with this method.final TabwithIcon(sprouts.Val<IconDeclaration> iconDeclaration) Allows you to dynamically model the icon displayed on the tab through a property bound to this tab.final TabwithIcon(IconDeclaration icon) Determines the icon to be displayed in the tab header based on aIconDeclaration, which is essentially just a path to the icon which should be displayed in the tab header.final TabAllows you to define the tooltip which should be displayed when hovering over the tab header.final TabAllows you to bind a string property to the tooltip of the tab.
-
Method Details
-
isSelectedIf
Use this to make the tab selected by default.- Parameters:
isSelected- The selected state of the tab.- Returns:
- A new
Tabinstance with the provided argument, which enables builder-style method chaining.
-
isSelectedIf
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
isSelectedIf
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
isSelectedIf
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
isEnabledIf
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
isEnabledIf
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
isEnabledIf
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
withIcon
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
withIcon
Determines the icon to be displayed in the tab header based on aIconDeclaration, 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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
withIcon
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
IconorImageIconclasses directly as a value for your property, instead you must use implementations of theIconDeclarationinterface, 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
IconDeclarationinterface, 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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
withTip
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
withTip
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
withHeader
-
withHeader
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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
add
Use this to add the contents UI to the tab.- Parameters:
contents- The contents which should be displayed in the tab.- Returns:
- A new
Tabinstance with the provided argument, which enables builder-style method chaining.
-
add
Use this to add the contents UI to the tab.- Parameters:
contents- The contents which should be displayed in the tab.- Returns:
- A new
Tabinstance with the provided argument, which enables builder-style method chaining.
-
onSelection
Use this to register and catch genericChangeEventbased 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
Tabinstance with the provided argument, which enables builder-style method chaining.
-
onMouseClick
Use this to register and catch genericMouseListenerbased mouse click events for this tab. This method adds the provided consumer lambda to theJTabbedPanethat this tab is added to.- Parameters:
onClick- The lambda instance which will be passed to theJTabbedPaneasMouseListener.- Returns:
- A new
Tabinstance with the provided argument, which enables builder-style method chaining.
-