如何eclipse jface组件中TitleAreaDialog对话框上方的关闭按钮进行置灰处理

描述如下:

第一个对话框:名称为A (TDialog.java)
第二个对关闭按钮进行隐藏后的对话框:名称为B (TDialog1.java)

原本想用隐藏就可以解决问题的。

描述:点击 A中按钮,弹出B
存在的问题:点击A中按钮,弹出B 但是用鼠标点击B时,[color=darkred]B就自动隐藏了,没法进行操作。[/color]最小化eclipse后,桌面上显示 B对话框,并且可以对其进行操作。(代码见附件,demo不存在此问题)所以我想要[color=red]对关闭按钮进行置灰处理[/color],不知道这样处理后能不能变通解决对上述问题。或者有什么更好的方法进行处理?demo代码如下:
另外:怎样对B的消息区设置提示信息 [color=red]【 setMessage("Hello World!");//这样会报错】[/color]

package test;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class [color=red]TDialog [/color]extends TitleAreaDialog {

public TDialog(Shell parentShell) {
    super(parentShell);
}

public static void main(String[] args) {
    final Display display = Display.getDefault();
    final Shell shell = new Shell();
    shell.setSize(327, 253);
    Button button = new Button(shell, SWT.NONE);
    button.setBounds(18, 20, 153, 25);
    button.setText("button");

    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TDialog1 tDialog = new TDialog1(shell);
            tDialog.open();
        }
    });
    shell.layout();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

}

package test;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class [color=red]TDialog1[/color] extends TitleAreaDialog {

final Display display = Display.getDefault();
final Shell shell = new Shell();

public  TDialog1(Shell parentShell) {
    super(parentShell);
          [color=red] //setMessage("Hello World!");//怎样set message?[/color]
}
[color=green]@Override
protected int getShellStyle() {
    return SWT.TITLE;// 隐藏关闭按钮,置灰时不需要这个方法
}[/color]

}

建议 1:
TitleAreaDialog不是这么用的,其实,TitleAreaDialog是一个已经被封装完后的控件,它有一定固定的使用模式.

[code="java"]public class TDialog extends TitleAreaDialog {
public TDialog(Shell parentShell) {
super(parentShell);
}
// JFACE的Dialog你完全不用自己去定义Shell, 只有SWT的Dialog才需要.
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));

    final Button button = new Button(container, SWT.NONE);
    button.setText("button");
    button.setBounds(26, 28, 44, 23);

    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            TDialog1 tDialog = new TDialog1(Display.getCurrent().getActiveShell());
            tDialog.open();
        }
    });

    return area;
}

protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

protected Point getInitialSize() {
    return new Point(500, 375);
}

}[/code]

解答1:

TitleAreaDialog 不能将关闭按钮置灰,

就算你的shell 的style 是: SWT.TITLE | SWT.MIN | SWT.MAX
看起来好像没有SWT.CLOSE, 只有存在上面三个style中的一个,这个窗口就有关闭按钮.

解答2:
[quote]B就自动隐藏了,没法进行操作[/quote]

是,你设置B dialog的style不对.

[code="java"]public class TDialog1 extends TitleAreaDialog {
public TDialog1(Shell parentShell) {
super(parentShell);
this.setShellStyle(SWT.APPLICATION_MODAL | SWT.TITLE);
}
}[/code]