0

当我在按钮栏中的对话框两端创建一个复选按钮和按钮时,它默认创建得很好,但是当我拖动或调整对话框大小时,复选按钮会从对话框的左端移开。当我调整对话框大小时,我应该如何防止它移动。这就是我覆盖按钮栏的方式。

       @Override
   protected void createButtonsForButtonBar(Composite parent) {
    super.createButtonsForButtonBar(parent);


    ((GridLayout) parent.getLayout()).numColumns = ((GridLayout) parent.getLayout()).numColumns+2;

    GridData checkData = new GridData(SWT.LEFT,
            SWT.BOTTOM,true,true);

    GridData labelData = new GridData(SWT.CENTER,
            SWT.CENTER,true,true);

    GridData closeLayoutData = new GridData(SWT.RIGHT,
            SWT.BOTTOM,true,true);

    parent.setLayoutData(closeLayoutData);

    Button close = getButton(IDialogConstants.CANCEL_ID);
    close.setText("Close");
    close.setLayoutData(closeLayoutData);
    close.setParent(parent);

    final Button checkButton = new Button(parent, SWT.CHECK);
    checkButton.setText("View All schedules");
    checkButton.setSelection(false);
    checkButton.setLayoutData(checkData);
    checkButton.setParent(parent);
    checkButton.moveAbove(close);
    checkButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (checkButton.getSelection()) {
                treeViewer.setFilters(new ViewerFilter[] { new ExistingExpiredScheduleFilter() });
            } else {
                treeViewer.setFilters(new ViewerFilter[] { new ExistingScheduleFilter() });
            }
        }
    });


    Label label = new Label(parent,SWT.HORIZONTAL);
    label.setLayoutData(labelData);
    label.setParent(parent);
    label.moveAbove(close);

}
4

1 回答 1

1

这有效:

    protected void createButtonsForButtonBar(Composite parent)
    {
        final GridLayout layout = (GridLayout)parent.getLayout();
        layout.numColumns += 2;
        layout.makeColumnsEqualWidth = false;

        parent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));    

        final Button checkButton = new Button(parent, SWT.CHECK);
        checkButton.setText("View All schedules");
        checkButton.setSelection(false);
        checkButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        // Left out selection code for clarity

        final Label label = new Label(parent, SWT.NONE);
        label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);

        createButton(parent, IDialogConstants.CANCEL_ID, "Close", false);
    }

没有必要打电话setParent。我已经按顺序创建了东西,因此无需重新排序。

于 2013-09-30T09:27:31.670 回答