简短的回答:
使用StyledText而不是标签 - 万物平等的。
详细的解答:
有一些错误的(120256是一个很好的切入点)在GTK这个“功能”他们大多标志着彼此的复制品,大部分他们回到gtk + 2.4/2.6一些标记固定。然而,2011年的gtk2 +版本2.22(Maverick Market),错误似乎非常有弹性。
在阅读了这个错误报告之后,我为wordwrap关键字整理了SWT源代码树,看起来像Steve Northover男孩用StyledText控件比使用标签控件更好地解决了bug。
我重复使用了Favonius测试用例(thx很多Favonius ;-),而且这看起来确实是很好的预兆。
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class RightAlign2
{
public static void main(String[] args)
{
Display display = new Display();
Shell shell = new Shell(display);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
shell.setLayout(layout);
shell.setText("Alignment Test");
String[] labelTexts = new String[]{"label 1:","Another label:","Another label with wrapped text:"};
for (String labelText : labelTexts)
{
StyledText fieldText = new StyledText(shell, SWT.RIGHT |SWT.WRAP | SWT.BORDER);
fieldText.setText(labelText);
GridData labelGridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
labelGridData.widthHint = 100;
fieldText.setLayoutData(labelGridData);
Text textField = new Text(shell, SWT.BORDER);
GridData textGridData = new GridData(GridData.FILL_HORIZONTAL);
textGridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
textGridData.widthHint = 248;
textField.setLayoutData(textGridData);
}
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}