java - 如何更改 JFace 向导对话框中的“后退”和“下一步”按钮位置?

标签 java eclipse swt jface wizard

我创建了一个自定义 JFace 向导对话框来添加按钮。我找到了一种方法来更改它们在布局中的位置(例如将它们放在“取消”和“完成”按钮之间),但当我尝试将它们放在“上一个”和“下一个”按钮之间时,它不起作用。

代码如下:

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

    Button nextButton = getButton(IDialogConstants.NEXT_ID);
    nextButton.setText(NEXT_LABEL);
    Button backButton = getButton(IDialogConstants.BACK_ID);
    backButton.setText(BACK_LABEL);
    Button cancelButton = getButton(IDialogConstants.CANCEL_ID);
    cancelButton.setText(CANCEL_LABEL);
    Button finishButton = getButton(IDialogConstants.FINISH_ID);
    finishButton.setText(FINISH_LABEL);

    rejectButton = super.createButton(parent, REJECT_ID, REJECT_LABEL, false);
    rejectButton.moveAbove(nextButton);
    setButtonLayoutData(rejectButton);

    acceptButton = super.createButton(parent, ACCEPT_ID, ACCEPT_LABEL, false);
    acceptButton.moveBelow(rejectButton);
    setButtonLayoutData(acceptButton);

}

当我查看向导时,我发现“上一个”和“下一个”按钮之间的间距比其他按钮更窄。看起来它们被绑在一起或者类似的东西......

还有其他解决方案可以改变他们的立场吗?

谢谢:)

最佳答案

毕竟,解决方案非常简单 =)

“后退”和“下一步”按钮在主组合内有自己的父组合:

private Composite createPreviousAndNextButtons(Composite parent) {
    // increment the number of columns in the button bar
    ((GridLayout) parent.getLayout()).numColumns++;
    Composite composite = new Composite(parent, SWT.NONE);
    // create a layout with spacing and margins appropriate for the font
    // size.
    GridLayout layout = new GridLayout();
    layout.numColumns = 0; // will be incremented by createButton
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    composite.setLayout(layout);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER
            | GridData.VERTICAL_ALIGN_CENTER);
    composite.setLayoutData(data);
    composite.setFont(parent.getFont());
    backButton = createButton(composite, IDialogConstants.BACK_ID,
            IDialogConstants.BACK_LABEL, false);
    nextButton = createButton(composite, IDialogConstants.NEXT_ID,
            IDialogConstants.NEXT_LABEL, false);
    return composite;

因此,我将重写方法的代码更改为:

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

    Button cancelButton = getButton(IDialogConstants.CANCEL_ID);
    cancelButton.setText(CANCEL_LABEL);
    Button finishButton = getButton(IDialogConstants.FINISH_ID);
    finishButton.setText(FINISH_LABEL);

    rejectButton = super.createButton(parent, REJECT_ID, REJECT_LABEL, false);
    setButtonLayoutData(rejectButton);

    acceptButton = super.createButton(parent, ACCEPT_ID, ACCEPT_LABEL, false);
    acceptButton.moveBelow(rejectButton);
    setButtonLayoutData(acceptButton);

    if (super.getWizard().needsPreviousAndNextButtons()) {
        Button nextButton = getButton(IDialogConstants.NEXT_ID);
        nextButton.setText(NEXT_LABEL);
        Button backButton = getButton(IDialogConstants.BACK_ID);
        backButton.setText(BACK_LABEL);

        // change composite parent of back and next buttons.
        nextButton.setParent(parent);
        backButton.setParent(parent);
        ((GridLayout) parent.getLayout()).numColumns = ((GridLayout) parent.getLayout()).numColumns + 2;

        // defines buttons'order
        finishButton.moveBelow(null);
        cancelButton.moveAbove(finishButton);
        nextButton.moveAbove(cancelButton);
        acceptButton.moveAbove(nextButton);
        rejectButton.moveAbove(acceptButton);
        backButton.moveAbove(rejectButton);
    }   
}

=)

关于java - 如何更改 JFace 向导对话框中的“后退”和“下一步”按钮位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11842770/

相关文章:

Java SWT : How to make a button unclickable while a separate thread is running

java - 无法从 base64 字符串中获取完整的图像质量

java - org.apache.xalan.processor.TransformerFactoryImpl 上的 AbstractMethodError

java - 如何取消JSlider左侧部分的填充?

java - Wildfly Maven 插件未注册 Web 上下文

Eclipse写入控制台

java - 当之前的一些行在我自己的 Eclipse 编辑器中折叠时获取当前行

java - SWT 图像到 Base64 字符串

java - Hazelcast 连接到外部地址

android - 与 android 构建目标设置术语混淆