Class TitledTab

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, IconProvider

public class TitledTab extends Tab implements IconProvider

A TitledTab is a tab that has support for text, icon and a custom Swing component (called title component). Titled tab supports several properties that makes it possible to change the look (borders, colors, insets), layout (up, down, left, right).

Titled tab has a line based layout, i.e. the text, icon and title component are laid out in a line. The layout of the tab can be rotated, i.e. the text and the icon will be rotated 90, 180 or 270 degrees. The title component will not be rotated but moved so that the line layout will persist.

A titled tab has 3 rendering states:

  • Normal - The tab is selectable but not yet selected
  • Highlighted - The tab is either highlighted or selected
  • Disabled - The tab is disabled and cannot be selected or highlighted
Most of the properties for the tab can be configured for each of the tab rendering states.

Note: If only the normal state properties have been configured, the highlighted and disabled state will automatically use the same properties as for the normal state, see TitledTabProperties and TitledTabStateProperties.

TitledTab implements the IconProvider interface and overloads toString() so that both text and icon for the normal state is shown in the tab drop down list in a tabbed panel.

TitledTab supports mouse hovering. A HoverListener can be set in the TitledTabProperties. The hover listener receives a HoverEvent when the mouse enters or exits the tab. The hover event's source will be the affected titled tab.

See Also:
  • Constructor Details

    • TitledTab

      public TitledTab(String text, Icon icon, JComponent contentComponent, JComponent titleComponent)
      Constructs a TitledTab with a text, icon, content component and title component.
      Parameters:
      text - text or null for no text. The text will be applied to the normal state properties
      icon - icon or null for no icon. The icon will be applied to the normal state properties
      contentComponent - content component or null for no content component
      titleComponent - title component or null for no title component. The title component will be applied to all the states
      See Also:
  • Method Details

    • contains

      public boolean contains(int x, int y)
      Overrides:
      contains in class JComponent
    • inside

      public boolean inside(int x, int y)
      Overrides:
      inside in class Component
    • getNormalStateTitleComponent

      public JComponent getNormalStateTitleComponent()
      Gets the title component for the normal state
      Returns:
      title component or null if no title component
    • getHighlightedStateTitleComponent

      public JComponent getHighlightedStateTitleComponent()
      Gets the title component for the highlighted state
      Returns:
      title component or null if no title component
    • getDisabledStateTitleComponent

      public JComponent getDisabledStateTitleComponent()
      Gets the title component for the disabled state
      Returns:
      title component or null if no title component
    • setTitleComponent

      public void setTitleComponent(JComponent titleComponent)

      Sets the title component.

      This method is a convenience method for setting the same title component for all states.

      Parameters:
      titleComponent - the title component or null for no title component
    • setNormalStateTitleComponent

      public void setNormalStateTitleComponent(JComponent titleComponent)
      Sets the normal state title component
      Parameters:
      titleComponent - the title component or null for no title component
    • setHighlightedStateTitleComponent

      public void setHighlightedStateTitleComponent(JComponent titleComponent)
      Sets the highlighted state title component
      Parameters:
      titleComponent - the title component or null for no title component
    • setDisabledStateTitleComponent

      public void setDisabledStateTitleComponent(JComponent titleComponent)
      Sets the disabled state title component
      Parameters:
      titleComponent - the title component or null for no title component
    • setHighlighted

      public void setHighlighted(boolean highlighted)

      Sets if this TitledTab should be highlighted or not.

      Note: This will only have effect if this TitledTab is enabled and a member of a tabbed panel.

      Overrides:
      setHighlighted in class Tab
      Parameters:
      highlighted - true for highlight, otherwise false
    • setEnabled

      public void setEnabled(boolean enabled)

      Sets if this TitledTab should be enabled or disabled

      Note: since ITP 1.5.0 this method will change the enabled property in the TitledTabProperties for this tab. Enabled/disabled can be controlled by modifying the property or this method.

      Overrides:
      setEnabled in class Tab
      Parameters:
      enabled - true for enabled, otherwise false
    • getText

      public String getText()
      Gets the text for the normal state
      Returns:
      the text or null if no text
    • setText

      public void setText(String text)
      Sets the text for the normal state
      Parameters:
      text - the text or null for no text
    • getIcon

      public Icon getIcon()
      Gets the icon for the normal state
      Specified by:
      getIcon in interface IconProvider
      Returns:
      the icon or null if none
    • setIcon

      public void setIcon(Icon icon)
      Sets the icon for the normal state
      Parameters:
      icon - the icon or null for no icon
    • getProperties

      public TitledTabProperties getProperties()
      Gets the TitledTabProperties
      Returns:
      the TitledTabProperties for this TitledTab
    • toString

      public String toString()
      Gets the text for the normal state. Same as getText().
      Overrides:
      toString in class Component
      Returns:
      the text or null if no text
      Since:
      ITP 1.1.0
      See Also:
    • addMouseListener

      public void addMouseListener(MouseListener l)
      Adds a MouseListener to receive mouse events from this TitledTab.
      Overrides:
      addMouseListener in class Component
      Parameters:
      l - the MouseListener
    • removeMouseListener

      public void removeMouseListener(MouseListener l)
      Removes a MouseListener
      Overrides:
      removeMouseListener in class Component
      Parameters:
      l - the MouseListener to remove
    • getMouseListeners

      public MouseListener[] getMouseListeners()
      Gets the mouse listeners
      Overrides:
      getMouseListeners in class Component
      Returns:
      the mouse listeners
    • addMouseMotionListener

      public void addMouseMotionListener(MouseMotionListener l)
      Adds a MouseMotionListener to receive mouse events from this TitledTab.
      Overrides:
      addMouseMotionListener in class Component
      Parameters:
      l - the MouseMotionListener
    • removeMouseMotionListener

      public void removeMouseMotionListener(MouseMotionListener l)
      Removes a MouseMotionListener
      Overrides:
      removeMouseMotionListener in class Component
      Parameters:
      l - the MouseMotionListener to remove
    • getMouseMotionListeners

      public MouseMotionListener[] getMouseMotionListeners()
      Gets the mouse motion listeners
      Overrides:
      getMouseMotionListeners in class Component
      Returns:
      the mouse motion listeners
    • getShape

      public Shape getShape()
      Gets the Shape for the current active rendering state.
      Overrides:
      getShape in class Tab
      Returns:
      the Shape for the active rendering state, null if no special shape
      Since:
      ITP 1.2.0
    • setTabbedPanel

      protected void setTabbedPanel(TabbedPanel tabbedPanel)
      Description copied from class: Tab
      Called by the tabbed panel when the tab becomes a member or is no longer a member of the tabbed panel
      Overrides:
      setTabbedPanel in class Tab
      Parameters:
      tabbedPanel - tabbed panel that this tab is a member of or null if this tab is no longer a member o a tabbed panel
    • setUI

      public void setUI(PanelUI ui)
      Overrides:
      setUI in class JPanel
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JPanel
    • setOpaque

      public void setOpaque(boolean opaque)
      Overrides:
      setOpaque in class JComponent