Skip to content

Separator

greipadmin edited this page Dec 5, 2018 · 9 revisions

Introduction

The Separator widget is composed of a line and optionally an text and an image.

  1. A simple Separator without image and default property values.
  2. A Separator with image, text and line style LineStyle.Dot.
  3. This Separator has custom background and foreground colors in combination with line style LineStyle.ShadowOut. The long title text was shortened.
  4. A Separator with customized font and colors and line style LineStyle.Solid.

Constructors

  • Separator(Composite parent, int style) or
  • Separator(Composite parent, int style, LineStyle lineStyle)
    • parent, the parent Composite
    • style, the style flags SWT.VERTICAL or SWT.HORIZONTAL. The default is SWT.HORIZONTAL.
    • lineStyle, the style of the line. Default is LineStyle.ShadowIn.

Methods

  • setText(String) set the text to show.
  • setImage(Image) set the optional image.
  • setOrientation(int) defines the orientation of the widget (SWT.HORIZONTAL or SWT.VERTICAL).

Colors and font

  • setBackground(Color) sets the background color.
  • setForeground(Color) sets the text color.
  • setLineColor(Color) sets the line color. This color is used for all line styles excluding LineStyle.ShadowIn and LineStyle.ShadowOut. Default is the defined foreground color.
  • setFont(Font) sets the text font.

Margins and spacing

  • setIndent(int) defines the distance between the left border and the image in pixels.
  • setSpacing(int) defines the space beween image and text in pixels.
  • setMarginWidth(int) and setMarginHeight(int) sets the widgets margins.

Line style

  • setLineStyle(LineStyle) defines the style of the line.
  • setLineCap(int), setLineWidth(int) and setLineDashs(int[]) sets the SWT line properties in equivalence to the GC methods.

Example

...
final Separator separator = new Separator(shell, SWT.HORIZONTAL);

separator.setText("Additional informations");
separator.setMarginHeight(5);
separator.setMarginWidth(5);
separator.setLineStyle(LineStyle.Dot);

final InputStream stream = Snippet5.class.getResourceAsStream("ico_info.png");
separator.loadImage(stream);

separator.addListener(SWT.Selection, e -> {
	final MessageBox msgBox = new MessageBox(shell);

	if (e.detail == Greip.IMAGE) {
		msgBox.setMessage("Image click.");
	} else {
		msgBox.setMessage("Click.");
	}

	msgBox.open();
});
...
Clone this wiki locally