如何在SwtJava中从相同的起点对齐标签



我创建了两个标签,它们具有完全相同的组合和相同的layoutData。我希望我的标签可以在屏幕的末尾看到,而且两个标签的起始字母应该从同一点开始。

Label l1 = new Label(composite, SWT.None);
l1.setLayoutData(new GridData(SWT.END, SWT.CENTER,false, false));
l1.setText("Unmapped");
Label l2 = new Label(composite, SWT.None);
l2.setLayoutData(new GridData(SWT.END, SWT.CENTER,false, false));
l2.setText("Mapped");

现在,使用上面的代码,我确实将输出指向屏幕的右端,但两个标签的起始字母都在两个不同的位置,而不是来自同一个起始位置。

我怎样才能做到这一点?

将标签放入另一个组合中。这个组合与其父项的末尾对齐,标签位于其父项的开头:

Composite labelComposite = new Composite(composite, SWT.NONE);
labelComposite.setLayout(new GridLayout());
labelComposite.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false));
Label l1 = new Label(labelComposite, SWT.LEAD);
l1.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
l1.setText("Unmapped");
Label l2 = new Label(labelComposite, SWT.LEAD);
l2.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
l2.setText("Mapped");

最新更新