我正在升级一个RCP应用程序以使用Eclipse 4.2.1。我遇到的问题之一是工具栏中文本的对齐方式已更改。
我可以使用以下摘录重现此问题,该摘录改编自标准SWT snippet。它只是创建了一个带有3个ToolItem的垂直ToolBar。每个项目都有一个图像和一些文本。
当我在Eclipse 3.7.2中运行此片段时,每个ToolItem的文本都是左对齐的。在Eclipse 4.2.1中,它是居中对齐的。我希望文本保持左对齐。设置样式为SWT.LEFT没有帮助。有什么建议吗?
我可以使用以下摘录重现此问题,该摘录改编自标准SWT snippet。它只是创建了一个带有3个ToolItem的垂直ToolBar。每个项目都有一个图像和一些文本。
当我在Eclipse 3.7.2中运行此片段时,每个ToolItem的文本都是左对齐的。在Eclipse 4.2.1中,它是居中对齐的。我希望文本保持左对齐。设置样式为SWT.LEFT没有帮助。有什么建议吗?
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
public class Snippet36 {
public static void main (final String [] args) {
Display display = new Display();
Image image = new Image (display, 16, 16);
Color color = display.getSystemColor (SWT.COLOR_RED);
GC gc = new GC (image);
gc.setBackground (color);
gc.fillRectangle (image.getBounds ());
gc.dispose ();
Shell shell = new Shell (display);
ToolBar toolBar = new ToolBar (shell, SWT.FLAT | SWT.BORDER | SWT.VERTICAL | SWT.RIGHT);
Rectangle clientArea = shell.getClientArea ();
toolBar.setLocation (clientArea.x, clientArea.y);
String[] labels = new String[] {"Short", "Quite a bit longer", "OK"};
for (int i=0; i<3; i++) {
ToolItem item = new ToolItem (toolBar, SWT.PUSH);
item.setText(labels[i]);
item.setImage (image);
}
toolBar.pack ();
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) {
display.sleep ();
}
}
image.dispose ();
display.dispose ();
}
}