Class CollapsableTitledBorder

java.lang.Object
javax.swing.border.AbstractBorder
javax.swing.border.TitledBorder
com.everdro1d.libs.swing.components.CollapsableTitledBorder
All Implemented Interfaces:
Serializable, Border

public class CollapsableTitledBorder extends TitledBorder
A collapsable titled border for JPanels and JTabbedPanes.

If using a JTabbedPane and you want to get the expanded status, implement a method like below.

     private boolean isOSTabbedPaneExpanded() {
         return !(osTabbedPane.getTabComponentAt(0) instanceof JLabel);
     }
 
See Also:
  • Constructor Details

    • CollapsableTitledBorder

      public CollapsableTitledBorder(JComponent panel, String titleText, boolean expandedDefault, boolean exclusive, int panelExpandedHeight, boolean showTabbedPaneSeparators)
      Creates a collapsable titled border for a JPanel or JTabbedPane.

      Default params set to:

       panelCollapsedHeight = 50
       
      Parameters:
      panel - the panel to add the border to
      titleText - the text to display in the title
      expandedDefault - true if the panel should be expanded by default
      exclusive - true if only one panel can be expanded at a time
      panelExpandedHeight - the height of the panel when expanded
      showTabbedPaneSeparators - true if the tabbed pane separators should be shown when expanded
    • CollapsableTitledBorder

      public CollapsableTitledBorder(JComponent panel, String titleText, boolean expandedDefault, boolean exclusive, int panelExpandedHeight, int panelCollapsedHeight, boolean showTabbedPaneSeparators)
      Creates a collapsable titled border for a JPanel or JTabbedPane.

      Default params set to:

       tabbedPaneExpandFunc = null
       
      Parameters:
      panel - the panel to add the border to
      titleText - the text to display in the title
      expandedDefault - true if the panel should be expanded by default
      exclusive - true if only one panel can be expanded at a time
      panelExpandedHeight - the height of the panel when expanded
      panelCollapsedHeight - the height of the panel when collapsed
      showTabbedPaneSeparators - true if the tabbed pane separators should be shown when expanded
    • CollapsableTitledBorder

      public CollapsableTitledBorder(JComponent panel, String titleText, boolean expandedDefault, boolean exclusive, int panelExpandedHeight, Consumer<JTabbedPane> tabbedPaneExpandFunc, boolean showTabbedPaneSeparators)
      Creates a collapsable titled border for a JPanel or JTabbedPane.

      Default params set to:

       panelCollapsedHeight = 50
       
      Parameters:
      panel - the panel to add the border to
      titleText - the text to display in the title
      expandedDefault - true if the panel should be expanded by default
      exclusive - true if only one panel can be expanded at a time
      panelExpandedHeight - the height of the panel when expanded
      tabbedPaneExpandFunc - a function to call when the tabbed pane is expanded
      showTabbedPaneSeparators - true if the tabbed pane separators should be shown when expanded
    • CollapsableTitledBorder

      public CollapsableTitledBorder(JComponent panel, String titleText, boolean expandedDefault, boolean exclusive, int panelExpandedHeight)
      Creates a collapsable titled border for a JPanel or JTabbedPane.

      Default params set to:

       panelCollapsedHeight = 50
       tabbedPaneExpandFunc = null
       showTabbedPaneSeparators = false
       
      Parameters:
      panel - the panel to add the border to
      titleText - the text to display in the title
      expandedDefault - true if the panel should be expanded by default
      exclusive - true if only one panel can be expanded at a time
      panelExpandedHeight - the height of the panel when expanded
    • CollapsableTitledBorder

      public CollapsableTitledBorder(JComponent panel, String titleText, boolean expandedDefault, boolean exclusive, int panelExpandedHeight, int panelCollapsedHeight)
      Creates a collapsable titled border for a JPanel or JTabbedPane.

      Default params set to:

       tabbedPaneExpandFunc = null
       showTabbedPaneSeparators = false
       
      Parameters:
      panel - the panel to add the border to
      titleText - the text to display in the title
      expandedDefault - true if the panel should be expanded by default
      exclusive - true if only one panel can be expanded at a time
      panelExpandedHeight - the height of the panel when expanded
      panelCollapsedHeight - the height of the panel when collapsed
    • CollapsableTitledBorder

      public CollapsableTitledBorder(JComponent panel, String titleText, boolean expandedDefault, boolean exclusive, int panelExpandedHeight, Consumer<JTabbedPane> tabbedPaneExpandFunc)
      Creates a collapsable titled border for a JPanel or JTabbedPane.

      Default params set to:

       panelCollapsedHeight = 50
       showTabbedPaneSeparators = false
       
      Parameters:
      panel - the panel to add the border to
      titleText - the text to display in the title
      expandedDefault - true if the panel should be expanded by default
      exclusive - true if only one panel can be expanded at a time
      panelExpandedHeight - the height of the panel when expanded
      tabbedPaneExpandFunc - a function to call when the tabbed pane is expanded
    • CollapsableTitledBorder

      public CollapsableTitledBorder(JComponent panel, String titleText, boolean expandedDefault, boolean exclusive, int panelExpandedHeight, int panelCollapsedHeight, Consumer<JTabbedPane> tabbedPaneExpandFunc, boolean showTabbedPaneSeparators)
      Creates a collapsable titled border for a JPanel or JTabbedPane.
      Parameters:
      panel - the panel to add the border to
      titleText - the text to display in the title
      expandedDefault - true if the panel should be expanded by default
      exclusive - true if only one panel can be expanded at a time
      panelExpandedHeight - the height of the panel when expanded
      panelCollapsedHeight - the height of the panel when collapsed
      tabbedPaneExpandFunc - a function to call when the tabbed pane is expanded
      showTabbedPaneSeparators - true if the tabbed pane separators should be shown when expanded