1

RoundedRectangle にスクロールバーを 1 つ追加したかったのです。ルート図に 3 つの角丸長方形があります。ここで、角丸長方形のそれぞれにスクロールバーを追加したいと思います。角丸長方形や長方形の図形にスクロールバーを追加することはできますか? 私は次の方法を使用しました。しかし、それは私には何の姿も見せません。それを機能させる方法は?以下の例では、長方形を 1 つだけ追加しています。

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.RoundedRectangle;
import org.eclipse.draw2d.ScrollPane;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class RoundedRectangleTest {

    public static void main(String args[]) {

        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        shell.setText("Scrollpane Example");

        // Create a root figure and simple layout to contain all other figures
        Figure root = new Figure();
        root.setFont(shell.getFont());
        root.setLayoutManager(new XYLayout());

        ScrollPane scrollPane = new ScrollPane();

        RoundedRectangle r = new RoundedRectangle();
        r.setBackgroundColor(ColorConstants.yellow);
        Rectangle rect = new Rectangle(10, 10, 50, 50);
        r.setBounds(rect);

        scrollPane.setContents(r);

        root.add(scrollPane);

        FigureCanvas canvas = new FigureCanvas(shell, SWT.DOUBLE_BUFFERED);
        canvas.setBackground(ColorConstants.white);
        //canvas.setContents(scrollPane);
        LightweightSystem lws = new LightweightSystem(canvas);
        lws.setContents(root);

        shell.setSize(400, 350);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();

    }

}
4

1 に答える 1

1

角の丸い四角形を取得することはできませんでしたが、少なくとも通常の四角形では次のように機能します。

public class RoundedRectangleTest {
    public static void main(String args[]) {
        Display d = Display.getDefault();
        final Shell shell = new Shell(d);

        LightweightSystem lws = new LightweightSystem(shell);
        final Figure contents = new Figure();
        lws.setContents(contents);
        contents.setLayoutManager(new GridLayout());

        IFigure rectangleFigure = createFigure();
        ScrollPane pane = new ScrollPane();

        /* delete following two lines if scrollbars not always visible */
        pane.setHorizontalScrollBarVisibility(ScrollPane.ALWAYS);
        pane.setVerticalScrollBarVisibility(ScrollPane.ALWAYS);
        pane.setContents(rectangleFigure);
        contents.add(pane);

        shell.open();
        shell.setText("Scrollpane Example");
        while (!shell.isDisposed()) {
            if (!d.readAndDispatch())
                d.sleep();
        }
    }

    private static IFigure createFigure() {
        RectangleFigure rectangleFigure = new RectangleFigure();
        rectangleFigure.setBackgroundColor(ColorConstants.yellow);
        rectangleFigure.setSize(100, 100);
        return rectangleFigure;
    }
}

たぶん、これを出発点として使用して、似てFigureいるRectangleFigureが角が丸いものを作成できます。

于 2012-07-24T15:23:59.980 に答える