java 如何设置 SWT 标签填充?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3609944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:38:53  来源:igfitidea点击:

How to set SWT label padding?

javalayoutswtjface

提问by kostja

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 Compositeand TableWrapData for the Labels

当我将文本分配给 my 时Labels,它们会非常紧密地环绕它,有时会切掉“p”、“y”等类似字符的下边缘。我想在文本和边框之间有一些填充。我使用 TableWrapLayout 作为父级Composite和 TableWrapData 作为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

我们正在使用 FormToolkit 进行一致的设计,恕我直言,这对边框绘制没有影响

采纳答案by Mohsen

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().

SWT 中的Layout(如GridLayout)和LayoutData(如GridData)对象只能控制控件外的间距(因此它们只能设置边距,不能设置填充)。为了改变控制端本身,你只能使用setSize()setBound()

回答by DavidL

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

(多年后的答案,但仍然是答案......)

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

回答by Simon Voggeneder

Quoting my answer to a similar question:

引用我对类似问题的回答:

I also wrestled with this issue. Labeldoes not support padding. I wound up using StyledTextinstead.

   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.

我也纠结于这个问题。Label不支持填充。我最终使用了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);

这对我有用。