4

Eclipse 4.2.1 を使用するように RCP アプリケーションをアップグレードしています。私が抱えている問題の 1 つは、ツールバーのテキストの配置が変更されたことです。

標準のSWT スニペットを改変した次のスニペットで問題を再現できます。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 ();
  }
}
4

1 に答える 1

0

Eclipse 4.2.1で試してみたところ、これが得られました。

ここに画像の説明を入力

すべて正常に動作します。

どのバージョンの SWT を使用していますか?

于 2012-11-23T11:31:31.973 に答える