Class TitledSeparator

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class TitledSeparator extends JPanel
TitledSeparator is a component used for separating components on a panel or in a GUI. Each TitledSeparator is comprised of a title part and a graphical line. This component is preferred over TitledBorder when no full border is desired. To see this component in action, please refer to the TitledSeparator Demo.

Usage

This class presents a large number of constructors. As such, configurating the TitledSeparator can be wholly achieved at construction time. The list below shows the available constructors for this.

 TitledSeparator(String text)
 TitledSeparator(String text, int textAlignment)
 TitledSeparator(String text, int type, int textAlignment)
 TitledSeparator(JComponent component, int textAlignment)
 TitledSeparator(JComponent component, int type, int textAlignment)
 TitledSeparator(JComponent component, Border border, int alignment)
 TitledSeparator(JComponent component, int type, int textAlignment, int barAlignment)
 TitledSeparator(JComponent component, Border border, int textAlignment, int barAlignment)
 

Alternatively, you may use the empty constructor. When this approach is used, the text, border, text alignment and border alignment will need to be explicitly set. For example:-

 TitledSeparator separator = new TitledSeparator();
 separator.setLabelComponent(new JLabel("Configured TitledSeparator"));
 separator.setTextAlignment(right);
 separator.setBarAlignment(center);
 separator.setSeparatorBorder(new PartialEtchedBorder(PartialSide.SOUTH));
 

Please note, that this class should be constructed and modified from the EDT.

See Also:
  • Field Details

  • Constructor Details

    • TitledSeparator

      public TitledSeparator()
      Creates the default titled separator.
    • TitledSeparator

      public TitledSeparator(String text)
      Creates a default titled separator with the specified text.
      Parameters:
      text - the title of this titled separator
    • TitledSeparator

      public TitledSeparator(String text, int textAlignment)
      Creates a titled separator with the specified text and alignment. The alignment determines whether the text will lye on the right or left of the separator line.
      Parameters:
      text - the title of this titled separator
      textAlignment - Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
    • TitledSeparator

      public TitledSeparator(String text, int type, int textAlignment)
      Creates a titled separator with the specified text, border type and alignment. The alignment determines whether the text will lye on the right or left of the separator line.
      Parameters:
      text - the title of this titled separator
      type - the style of border used as the separator line. Valid values are:- TitledSeparator.TYPE_PARTIAL_ETCHED, TitledSeparator.TYPE_PARTIAL_LINE or TitledSeparator.TYPE_PARTIAL_GRADIENT_LINE.
      textAlignment - Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
    • TitledSeparator

      public TitledSeparator(JComponent labelComponent, int textAlignment)
      Creates a titled separator with the specified component and alignment. The alignment determines whether the specified component will lye on the right or left of the separator line.
      Parameters:
      labelComponent - the component to be used as the titled part of this separator
      textAlignment - Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
    • TitledSeparator

      public TitledSeparator(JComponent labelComponent, int type, int textAlignment)
      Creates a titled separator with the specified component, border type and alignment. The alignment determines whether the specified component will lye on the right or left of the separator line.
      Parameters:
      labelComponent - the component to be used as the titled part of this separator
      type - the style of border used as the separator line. Valid values are:- TitledSeparator.TYPE_PARTIAL_ETCHED, TitledSeparator.TYPE_PARTIAL_LINE or TitledSeparator.TYPE_PARTIAL_GRADIENT_LINE.
      textAlignment - Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
    • TitledSeparator

      public TitledSeparator(JComponent labelComponent, Border border, int textAlignment)
      Creates a titled separator with the specified component, border and alignment. The alignment determines whether the specified component will lye on the right or left of the separator line.
      Parameters:
      labelComponent - the component to be used as the titled part of this separator
      border - the border to be used as the separator line
      textAlignment - Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
    • TitledSeparator

      public TitledSeparator(JComponent labelComponent, int type, int textAlignment, int barAlignment)
      Creates a titled separator with the specified component, border type, alignment and vertical alignment. The alignment determines whether the specified component will lye on the right or left of the separator line. The vertical alignment refers to the alignment of the separator line -- top, middle or bottom. Whenspecifyingg a border, the border is set with default values, for example: both TYPE_PARTIAL_LINE and TYPE_PARTIAL_LINE are configured with a 'thickness' of one pixel. If the the border required is not the default version, please use another constructor: TitledSeparator(component, border, alignment, verticalAlignment).
      Parameters:
      labelComponent - the component to be used as the titled part of this separator
      type - the style of border used as the separator line. Valid values are:- TitledSeparator.TYPE_PARTIAL_ETCHED, TitledSeparator.TYPE_PARTIAL_LINE or TitledSeparator.TYPE_PARTIAL_GRADIENT_LINE.
      textAlignment - Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
      barAlignment - Valid values are: SwingConstants.TOP, SwingConstants.CENTER or SwingConstants.BOTTOM.
    • TitledSeparator

      public TitledSeparator(JComponent labelComponent, Border border, int textAlignment, int barAlignment)
      Creates a titled separator with the specified component, border, alignment and vertical alignment. The alignment determines whether the specified component will lye on the right or left of the separator line. The vertical alignment refers to the alignment of the separator line -- top, middle or bottom.
      Parameters:
      labelComponent - the component to be used as the titled part of this separator
      border - the border to be used as the separator line
      textAlignment - Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
      barAlignment - Valid values are: SwingConstants.TOP, SwingConstants.CENTER or SwingConstants.BOTTOM.
  • Method Details

    • setLabelComponent

      public void setLabelComponent(JComponent labelComponent)
      Sets the labelComponent part of this Titled Separator.
      Parameters:
      labelComponent - the component holding the text to display as the title.
      See Also:
    • getLabelComponent

      public JComponent getLabelComponent()
      Returns the label part of this Titled Separator.
      Returns:
      the component holding the text to display as the title.
    • setSeparatorBorder

      public void setSeparatorBorder(Border border)
      Sets the border to be used as the graphical line region of this Titled Separator.
      Parameters:
      border - Any border of type: com.jidesoft.swing.PartialEtchedBorder, com.jidesoft.swing.PartialLineBorder or com.jidesoft.swing.PartialGradientLineBorder.
      See Also:
    • getSeparatorBorder

      public Border getSeparatorBorder()
      Returns the border type.
      Returns:
      the border type. Valid return values are: TitledSeparator.TYPE_PARTIAL_ETCHED, TitledSeparator.TYPE_PARTIAL_LINE, TitledSeparator.TYPE_PARTIAL_GRADIENT_LINE or -1 if the current border is none of the above.
    • setTextAlignment

      public void setTextAlignment(int textAlignment)
      Sets the texts horizontal alignment.
      Parameters:
      textAlignment - an int representing the texts horizontal position. Valid values are: SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING or SwingConstants.TRAILING.
      See Also:
    • getTextAlignment

      public int getTextAlignment()
      Returns the texts horizontal alignment.
      Returns:
      the texts horizontal alignment. Valid return values are: SwingConstants.LEFT, SwingConstants.RIGHT, or SwingConstants.CENTER.
    • setBarAlignment

      public void setBarAlignment(int barAlignment)
      Sets the bars vertical alignment.
      Parameters:
      barAlignment - Valid values are: SwingConstants.TOP, SwingConstants.CENTER or SwingConstants.BOTTOM.
      See Also:
    • getBarAlignment

      public int getBarAlignment()
      Returns the bars vertical alignment.
      Returns:
      the barsverticall alignment. Valid values are: SwingConstants.TOP, SwingConstants.CENTER or SwingConstants.BOTTOM.
    • validateTitledSeparator

      public void validateTitledSeparator()
      Responsible for configurating this TitledSeparator. This is the method through which all constructors ultimately feed.

      Creates a titled separator with the specified component, border, alignment and vertical alignment. The alignment determines whether the specified component will lye on the right or left of the separator line. The vertical alignment refers to the alignment of the separator line -- top, middle or bottom.