How to add a solid line border to a label in SWT and change the border color?

I want to style the standard SWT label by giving it a solid border and choosing a color for this border. I cannot find a way to do this by watching it online. Is it even supported? All I can do is simply apply the SWT.BORDER style to it, which is the border of the three-dimensional effect, which I seem to have little control over.

+3
source share
2 answers

JFace forms provide this in FormToolkit. See here .

The private BorderPainter class (lines 106-165) does what Mario already described in his answer: custom border painting around your widget. To make it work, you must add a BorderPainter, which is PaintListener, to your widget parent, see paintBordersFor(.)line 798.

I would not recommend adding jface forms as a dependency if you only need a border guard artist - too heavy. But this code should help you.

+2
source

Add a PaintListener to your label. In this Listener method, paintControlget the generated GC event and, using it, draw a rectangle with the same shape as your shortcut.

In fact, you can draw something on top of your label.

+2
source

Source: https://habr.com/ru/post/1779658/


All Articles