java - SWT/JFace 如何使选项卡窗口可滚动

标签 java tabs swt jface

使用选项卡窗口并为外壳指定固定大小,如果空间不足,如何使内容(即整个外壳)可滚动?这是 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/

相关文章:

java - 从路径中获取文件的大小

java - 在java中的for循环上运行JTabbedPanel

java - Windows下Eclipse SWT中使用64位XulRunner

java - JFace 数据绑定(bind)映射属性到 SWT 文本字段

java - java中泛型函数的多重扩展

java - 使 Websphere 上的 LTPA token 无效

java - 为什么Date对象在不同地域不同设备上的字符串格式不同?

tabs - 在 Textmate 中编程时,您如何默认使用 Soft Tabs?

java - JEdi​​torPane - 制作制表符空间

java - 防止监听器自行触发