gpt4 book ai didi

java - 滚动 Pane 到图

转载 作者:太空宇宙 更新时间:2023-11-04 08:08:40 24 4
gpt4 key购买 nike

我想在 RoundedRectangle 中添加一个滚动条。我在根图中有 3 个圆角矩形。现在我想向每个圆角矩形添加滚动条。是否有可能将滚动条添加到圆角矩形或矩形图形中?我用的是下面的方式。但它没有向我显示任何数字。如何让它发挥作用?在下面的示例中,我只添加了一个矩形。

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();

}

}

最佳答案

我没有设法获得圆角矩形,但以下至少适用于常规矩形:

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;
}
}

也许您可以以此为起点,创建一个类似于 RectangleFigureFigure,但带有圆角。

关于java - 滚动 Pane 到图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11633509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com