为什么调用setMaximized不起作用?

时间:2016-05-29 05:55:07

标签: java swt jface

我创建了一个JFace ApplicationWindow,我希望它打开最大化,但它不起作用,基本代码结构如下,我只是删除了创建UI和数据绑定的代码,在窗口上设置标题是工作,但窗口没有最大化,为什么?

public class XToolMain extends ApplicationWindow {
    private final static FormToolkit formToolkit = new FormToolkit(Display.getDefault());

    private String currentTx;

    private Head headBean;

    private Object bodyBean;

    private DataBindingContext bindingContext ;

    private SimpleDateFormat dateTime = new SimpleDateFormat("yyyyMMddHHmmss");

    private SimpleDateFormat timestamp = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    private Config config;

    private String app_id;

    private String target;

    private Text platformAdressText;

    private ScrolledForm form;

    private Text toOrgIdText;

    private Text toOrgNameText;

    private Text fromOrgIdText;

    private Text fromOrgNameText;

    private Text toTGOrgIdText;

    private Button genButton;

    /**
     * Create the application window.
     */
    public XToolMain() {
        super(null);
        setShellStyle(SWT.MIN | SWT.MAX | SWT.RESIZE);

        config = new Config();

        //-Datfsim.platformAddress=9.152.47.241 -Datfsim.toOrgId=313701099012 -Datfsim.toOrgName=贵州银行 -Datfsim.fromOrgId=cfcapolice1 -Datfsim.fromOrgName=测试公安机关
        String c1 = System.getProperty("atfsim.platformAddress");
        String c2 = System.getProperty("atfsim.toOrgId");
        String c3 = System.getProperty("atfsim.toTGOrgId");
        String c4 = System.getProperty("atfsim.toOrgName");
        String c5 = System.getProperty("atfsim.fromOrgId");
        String c6 = System.getProperty("atfsim.fromOrgName");

        config.setPlatformAddress(c1);
        config.setToOrgId(c2);
        config.setToTGOrgId(c3);
        config.setToOrgName(c4);
        config.setFromOrgId(c5);
        config.setFromOrgName(c6);
    }

    /**
     * Create contents of the application window.
     * @param parent
     */
    @Override
    protected Control createContents(Composite parent) {

        // code to create UI

        initDataBindings();

        return container;
    }




    public static void main(String args[]) {
        Realm.runWithDefault(SWTObservables.getRealm(Display.getCurrent()), new Runnable() {
            public void run() {
                try {
                    XToolMain window = new XToolMain();
                    window.setBlockOnOpen(true);
                    window.open();
                    formToolkit.dispose();
                    SWTResourceManager.dispose();
                    Display.getCurrent().dispose();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

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

        newShell.setText("报文生成工具");
        newShell.setMaximized(true);
    }


    protected void initDataBindings() {
        // data binding code
    }
}

1 个答案:

答案 0 :(得分:3)

setMaximized放入constrainShellSize将有效:

@Override
protected void constrainShellSize() {
    super.constrainShellSize();
    getShell().setMaximized(true);
}

归功于https://vzurczak.wordpress.com/2013/08/18/maximizing-a-jface-dialog-programmatically/

相关问题