Class Separator

java.lang.Object
com.codename1.ui.Component
com.codename1.components.Separator
All Implemented Interfaces:
Animation, Editable, StyleListener

public class Separator extends Component

A rule that divides one group of controls from the next.

Every desktop toolkit draws one -- NSBox in separator mode, WinUI's MenuFlyoutSeparator and navigation separators, GtkSeparator -- and Codename One had no component for it, so applications drew their own out of a Label with a bottom border, or a Container with a fixed height and a background colour. Those look approximately right on one platform and wrong everywhere else, because the thing that differs between platforms is exactly the part they hard-code: the thickness, the colour, and how much air sits either side of it.

All three come from the Separator UIID. The rule itself is the style's border where there is one and its background colour otherwise, the air either side is the style's margin, and the thickness is the separatorThicknessMM theme constant. A theme that says nothing gets a one-pixel line in the foreground colour.

Container settings = new Container(BoxLayout.y());
settings.add(new Label("Appearance"))
        .add(new Separator())
        .add(new Label("Privacy"));

A separator is not focusable and is skipped by keyboard traversal: it is decoration, and stopping on it with Tab would be a bug on every platform.

  • Field Details

    • HORIZONTAL

      public static final int HORIZONTAL
      A rule that runs left to right, dividing the rows of a vertical stack.
      See Also:
    • VERTICAL

      public static final int VERTICAL
      A rule that runs top to bottom, dividing the columns of a horizontal row.
      See Also:
  • Constructor Details

    • Separator

      public Separator()
      A horizontal separator.
    • Separator

      public Separator(int orientation)

      A separator running in the given direction.

      Parameters
      • orientation: #HORIZONTAL or #VERTICAL
  • Method Details

    • getOrientation

      public int getOrientation()

      The direction this rule runs in.

      Returns

      #HORIZONTAL or #VERTICAL

    • setOrientation

      public void setOrientation(int orientation)

      Sets the direction this rule runs in.

      Parameters
      • orientation: #HORIZONTAL or #VERTICAL
    • getThickness

      protected int getThickness()

      The rule's thickness in pixels, from the separatorThicknessMM theme constant.

      Never zero. A theme is free to ask for a hairline, and a hairline on a high density screen rounds to zero millimetres worth of pixels -- which would make the separator invisible rather than thin, and invisible is the one thing it must not be.

      Returns

      the thickness in pixels, at least 1

    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

      Parameters
      • g: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component