Class JXTitledSeparator

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

@JavaBean public class JXTitledSeparator extends JXPanel

A simple horizontal separator that contains a title.

JXTitledSeparator allows you to specify the title via the setTitle(java.lang.String) method. The title alignment may be specified by using the setHorizontalAlignment(int) method, and accepts all the same arguments as the JLabel.setHorizontalAlignment(int) method.

In addition, you may specify an Icon to use with this separator. The icon will appear "leading" the title (on the left in left-to-right languages, on the right in right-to-left languages). To change the position of the title with respect to the icon, call setHorizontalTextPosition(int).

The default font and color of the title comes from the LookAndFeel, mimicking the font and color of the TitledBorder

Here are a few example code snippets:


  //create a plain separator
  JXTitledSeparator sep = new JXTitledSeparator();
  sep.setTitle("Customer Info");

  //create a separator with an icon
  sep = new JXTitledSeparator();
  sep.setTitle("Customer Info");
  sep.setIcon(new ImageIcon("myimage.png"));

  //create a separator with an icon to the right of the title,
  //center justified
  sep = new JXTitledSeparator();
  sep.setTitle("Customer Info");
  sep.setIcon(new ImageIcon("myimage.png"));
  sep.setHorizontalAlignment(SwingConstants.CENTER);
  sep.setHorizontalTextPosition(SwingConstants.TRAILING);
 
Author:
rbair
See Also:
  • Constructor Details

    • JXTitledSeparator

      public JXTitledSeparator()
      Creates a new instance of JXTitledSeparator. The default title is simply an empty string. Default justification is LEADING, and the default horizontal text position is TRAILING (title follows icon)
    • JXTitledSeparator

      public JXTitledSeparator(String title)
      Creates a new instance of JXTitledSeparator with the specified title. Default horizontal alignment is LEADING, and the default horizontal text position is TRAILING (title follows icon)
    • JXTitledSeparator

      public JXTitledSeparator(String title, int horizontalAlignment)
      Creates a new instance of JXTitledSeparator with the specified title and horizontal alignment. The default horizontal text position is TRAILING (title follows icon)
    • JXTitledSeparator

      public JXTitledSeparator(String title, int horizontalAlignment, Icon icon)
      Creates a new instance of JXTitledSeparator with the specified title, icon, and horizontal alignment. The default horizontal text position is TRAILING (title follows icon)
  • Method Details

    • updateTitle

      protected void updateTitle()
      Implementation detail. Handles updates of title color and font on LAF change. For more details see swingx#451.
    • setTitle

      public void setTitle(String title)
      Sets the title for the separator. This may be simple html, or plain text.
      Parameters:
      title - the new title. Any string input is acceptable
    • getTitle

      public String getTitle()
      Gets the title.
      Returns:
      the title being used for this JXTitledSeparator. This will be the raw title text, and so may include html tags etc if they were so specified in #setTitle.
    • setHorizontalAlignment

      public void setHorizontalAlignment(int alignment)

      Sets the alignment of the title along the X axis. If leading, then the title will lead the separator (in left-to-right languages, the title will be to the left and the separator to the right). If centered, then a separator will be to the left, followed by the title (centered), followed by a separator to the right. Trailing will have the title on the right with a separator to its left, in left-to-right languages.

      LEFT and RIGHT always position the text left or right of the separator, respectively, regardless of the language orientation.

      Parameters:
      alignment - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING (the default) or TRAILING.
      Throws:
      IllegalArgumentException - if the alignment does not match one of the accepted inputs.
      See Also:
    • getHorizontalAlignment

      public int getHorizontalAlignment()
      Returns the alignment of the title contents along the X axis.
      Returns:
      The value of the horizontalAlignment property, one of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.
      See Also:
    • setHorizontalTextPosition

      public void setHorizontalTextPosition(int position)
      Sets the horizontal position of the title's text, relative to the icon.
      Parameters:
      position - One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING, or TRAILING (the default).
      Throws:
      IllegalArgumentException - if the position does not match one of the accepted inputs.
    • getHorizontalTextPosition

      public int getHorizontalTextPosition()
      Returns the horizontal position of the title's text, relative to the icon.
      Returns:
      One of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.
      See Also:
    • getComponentOrientation

      public ComponentOrientation getComponentOrientation()
      Overrides:
      getComponentOrientation in class Component
    • setComponentOrientation

      public void setComponentOrientation(ComponentOrientation o)
      Overrides:
      setComponentOrientation in class Component
    • setIcon

      public void setIcon(Icon icon)
      Defines the icon this component will display. If the value of icon is null, nothing is displayed.

      The default value of this property is null.

      See Also:
    • getIcon

      public Icon getIcon()
      Returns the graphic image (glyph, icon) that the JXTitledSeparator displays.
      Returns:
      an Icon
      See Also:
    • setForeground

      public void setForeground(Color foreground)
      Overrides:
      setForeground in class JComponent
    • setFont

      public void setFont(Font font)
      Overrides:
      setFont in class JComponent