JFace应用程序窗口的最小大小

时间:2014-11-20 10:00:40

标签: java swt jface

我刚开始使用JFace / SWT中的GUI编程。在我使用普通的SWT窗口(http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.wb.ercp.doc.user%2Fhtml%2Fwizards%2FeRCP%2Fapplication_window.html)之前,我今天第一次尝试了JFace应用程序窗口。

现在我要设置此窗口的最小大小。在SWT中,它与

一起使用
shell.setMinimumSize(100,100)

但在我的org.eclipse.jface.window.ApplicationWindow中没有这样的方法..

我已经尝试了

this.createShell().setMinimumSize(100, 100);

(我的实现"公共类MainView扩展了ApplicationWindow {")

但它没有用。

this.getShell()

返回null。

顺便说一句,我在gernal中搜索了一篇关于JFace的文档,特别是在Application Window中。但我找不到任何真正优秀和广泛的东西。

SWT中的文档,尤其是JFace的文档令人非常失望。太糟糕了,因为它有很好的功能。

您有什么经历?

2 个答案:

答案 0 :(得分:4)

覆盖configureShell方法并在那里设置最小尺寸:

@Override
protected void configureShell(Shell newShell)
{
  super.configureShell(newShell);

  newShell.setMinimumSize(100, 100);
}

答案 1 :(得分:0)

createShell 方法的文档中可以看出,它创建了一个新shell。您需要使用窗口的现有/创建的shell。

您可以从应用程序的父组合中获取它。请参阅以下代码段中的 createContents 方法:

package helloproject;

import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

public class HelloWorld extends ApplicationWindow {

    public HelloWorld() {
        super(null);
    }

    /**
     * Runs the application
     */
    public void run() {
        setBlockOnOpen(true);
        open();
        Display.getCurrent().dispose();
    }

    protected Control createContents(Composite parent) {
        // Create a Hello, World label
        Label label = new Label(parent, SWT.CENTER);
        label.setText("Hello, World");

        // Set the minimum size
        parent.getShell().setMinimumSize(200, 200);

        return label;
    }

    public static void main(String[] args) {
        new HelloWorld().run();
    }
}
相关问题