How to set SWT label padding?
Solution 1
Layout (such as GridLayout) and LayoutData (e.g. GridData) objects in SWT can only control spacing outside a control (so they may only set margins, not padding). In order to change control side itself you can only use setSize()
and setBound()
.
Solution 2
(Answer many years later, but still an answer...)
CLabel cl = new CLabel(shell, SWT.CENTER);
int padding = 5;
cl.setMargins(padding, padding, padding, padding);
Solution 3
Quoting my answer to a similar question:
I also wrestled with this issue.
Label
does not support padding. I wound up usingStyledText
instead.final StyledText text = new StyledText(parent, SWT.WRAP); final int padding = 5; text.setLeftMargin(padding); text.setRightMargin(padding); text.setTopMargin(padding); text.setBottomMargin(padding); text.setWordWrap(true); text.setCaret(null);
This did the trick for me.
kostja
We are here to learn :) Works and plays with scala, kafka, data, linux
Updated on June 04, 2022Comments
-
kostja almost 2 years
When i assign text to my
Labels
, they wrap around it very tightly, sometimes cutting the lower edges off 'p', 'y' and alike. I would like to have some padding between text and border. I am using a TableWrapLayout for the parentComposite
and TableWrapData for theLabels
TableWrapLayout layout = new TableWrapLayout(); layout.numColumns = 2; layout.bottomMargin = 10; layout.topMargin = 10; client.setLayout(layout); Label label= toolkit.createLabel(client, "", SWT.NONE);
We are using the FormToolkit for consistent design, IMHO this has no influence on border painting