Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使视图在EclipseRCP应用程序中可滚动?_Java_Eclipse Plugin_Eclipse Rcp - Fatal编程技术网

Java 如何使视图在EclipseRCP应用程序中可滚动?

Java 如何使视图在EclipseRCP应用程序中可滚动?,java,eclipse-plugin,eclipse-rcp,Java,Eclipse Plugin,Eclipse Rcp,到目前为止,我尝试的是: 在createPartControl中: ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); sc.setLayoutData(new GridData(GridData.FILL_BOTH)); sc.setExpandVertical(true); sc.setExpandHorizontal(true);

到目前为止,我尝试的是:

在createPartControl中:

ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
        sc.setLayoutData(new GridData(GridData.FILL_BOTH));
        sc.setExpandVertical(true);
        sc.setExpandHorizontal(true);
        sc.setSize(ApplicationWorkbenchWindowAdvisor.WIDTH, ApplicationWorkbenchWindowAdvisor.HEIGHT);
        final TabFolder tabFolder = new TabFolder(sc, SWT.TOP);
但这是行不通的。我的问题是,如果我调整程序窗口的大小,滚动条不会出现在我的视图中。有什么想法吗?

描述了使用它的两种方法,包括示例代码。综上所述:

  • 您可以在控件/组合本身上设置
    ScrolledComposite
    中包含的控件/组合的大小
  • 或者告诉您的
    ScrolledComposite
    用于其内容的最小大小

  • 目前,你两个都不做。您正在设置ScrolledComposite的大小,但除非您不使用布局管理器,否则这没有多大意义。在任何情况下,请参见上面的链接以获取一些官方示例代码。

    这是一段对我有用的代码:

        ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        Composite composite = new Composite(sc, SWT.NONE);
        sc.setContent(composite);
    
        Label lblRelation = new Label(composite, SWT.NONE);
        lblRelation.setBounds(10, 13, 74, 15);
        lblRelation.setText("Label name:");
        composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    

    通常在Eclipse视图中,我希望我的控件能够获取所有可用空间,并且只显示滚动条,否则控件会缩小到可用大小以下

    其他答案完全正确,但我想添加一个
    createPartControl
    方法(Eclipse4)的完整示例

    请注意,
    .fillDefaults()
    意味着
    .align(SWT.FILL,SWT.FILL)

    我通常使用此模式,因此创建了以下小助手方法:

    public static ScrolledComposite createScrollable(Composite parent, Consumer<Composite> scrollableContentCreator) {
        ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        Composite composite = new Composite(sc, SWT.NONE);
        sc.setContent(composite);
    
        scrollableContentCreator.accept(composite);
    
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);
        sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        return sc;
    }
    

    非常感谢!现在我学会了在问愚蠢的问题之前总是检查javadoc……无论是否调用
    setMinSize
    ,我都会得到相同的结果,这看起来很奇怪。。。无论哪种方式,当我的编辑器小于
    GridData
    中的大小提示时,滚动条都会出现。也许这是因为它是一个多页表单编辑器。。。
    public static ScrolledComposite createScrollable(Composite parent, Consumer<Composite> scrollableContentCreator) {
        ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        Composite composite = new Composite(sc, SWT.NONE);
        sc.setContent(composite);
    
        scrollableContentCreator.accept(composite);
    
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);
        sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        return sc;
    }
    
        createScrollable(container, composite -> {
            composite.setLayout(new FillLayout());
            // fill composite with controls
        });