简体   繁体   English

如何设置SWT标签填充?

[英]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. 当我将文本分配给我的Labels ,它们会非常紧密地环绕它,有时会将下边缘切掉'p','y'等。 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作为Labels的父Composite和TableWrapData

    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 我们使用FormToolkit进行一致的设计,恕我直言,这对边框绘画没有影响

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). SWT中的布局(例如GridLayout)和LayoutData(例如GridData)对象只能控制控件外的间距(因此它们只能设置边距而不是填充)。 In order to change control side itself you can only use setSize() and setBound() . 为了更改控件端本身,您只能使用setSize()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. Label不支持填充。 I wound up using StyledText instead. 我最后使用了StyledText

  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. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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