使用选项卡窗口并为外壳指定固定大小,如果空间不足,如何使内容(即整个外壳)可滚动?这是 shell、选项卡主机还是单个选项卡的设置?
最佳答案
使用 ScrolledComposite
其中包含您的全部内容。这样,如果没有足够的空间来显示它,它将滚动。
下面的代码应该可以让您了解它的工作原理:
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
// Create the ScrolledComposite to scroll horizontally and vertically
ScrolledComposite scrolledComp = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
// Create a child composite for your content
Composite content = new Composite(scrolledComp, SWT.NONE);
content.setLayout(new FillLayout());
// Create some content
new Button(content, SWT.PUSH).setText("Button1");
new Button(content, SWT.PUSH).setText("Button2");
// add content to scrolled composite
scrolledComp.setContent(content);
// Set the minimum size (in this case way too large)
scrolledComp.setMinSize(400, 400);
// Expand both horizontally and vertically
scrolledComp.setExpandHorizontal(true);
scrolledComp.setExpandVertical(true);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
运行它,减小窗口大小,您将看到滚动条。
关于java - SWT/JFace 如何使选项卡窗口可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12349497/