简体   繁体   中英

How to set SWT label padding?

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 parent Composite and TableWrapData for the Labels

    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

Layout (such as GridLayout) and LayoutData (eg 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() .

(Answer many years later, but still an answer...)

CLabel cl = new CLabel(shell, SWT.CENTER);
int padding = 5;
cl.setMargins(padding, padding, padding, padding);

Quoting my answer to a similar question:

I also wrestled with this issue. Label does not support padding. I wound up using StyledText 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM