0
凡例ビューを作成していて、シェルの内部に矩形があり、その後に色を記述するラベルがあるはずです。私は通常のコンポジットだけを使ってビューを得ることができましたが、凡例は画面を越えて続き、ウィンドウを大きくせずに見ることはできません。私はシェルのためにscrolledCompositeビューを使用しようとしていますが、プログラムを実行すると何も表示されません。ScrollledCompositeの中にコンテンツを表示する方法
public void createPartControl(Composite parent)
{
display = parent.getDisplay();
parent.setLayout(new FillLayout());
sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
LegendView.composite = new Composite(sc, SWT.NONE);
RowLayout layout = new RowLayout();
layout.wrap = true;
layout.spacing = 5;
composite.setLayout(layout);
}
public static void addRectangle(String legendMessage)
{
final String propId = legendMessage;
final String[] s = propId.split(",");
if (display != null)
{
display.syncExec(new Runnable()
{
@Override
public void run()
{
// Creating the color using the RBG values
final Color color =
new Color(display, Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2]));
// Creating a canvas for which the rectangle can be drawn on
Canvas canvas = new Canvas(composite, SWT.NONE);
// Maybe set the bounds of the canvas
canvas.addPaintListener(new PaintListener()
{
public void paintControl(PaintEvent e)
{
e.gc.drawRectangle(1, 1, 50, 60);
e.gc.setBackground(color);
e.gc.fillRectangle(2, 2, 49, 59);
}
});
// Disposing the color after it has been used
canvas.addDisposeListener(new DisposeListener()
{
public void widgetDisposed(DisposeEvent e)
{
color.dispose();
}
});
// Creating a label and setting the font
Label label = new Label(composite, SWT.NULL);
Font boldFont = new Font(label.getDisplay(), new FontData("Arial", 12, SWT.BOLD));
label.setFont(boldFont);
label.setText(s[3]);
composite.redraw();
composite.layout(true);
sc.setContent(composite);
}
});
}
}
私は、別のクラスに矩形を追加します。私はSWTを使用することでかなり新しいです。そして、例を見て、スクロールされたCompositeのためのドキュメントを読んだ後、これは私がそれを解釈したものです。どんな助けでも大歓迎です。
。彼らが現れる唯一の時間は、私が窓をとても小さくして、凡例の最初の項目にスクロールできる量と他の部分が隠されているときです。キャンバスやラベルが閾値以下になり、スクロールバーを表示するコンポジットにシェルの特定のサイズをハードコードする必要がないことが通知される方法はありますか? – Justin
あなたがScrolledCompositeについて唯一知っているのは、最小サイズです。コンポジットにGridLayoutなどのレイアウトを使用すると、computeSizeで計算されたサイズをより詳細に制御できます。 –