renyiyong 2008-06-26 16:53
浏览 290
已采纳

如何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]

}

  • 写回答

3条回答 默认 最新

  • lggegegmail 2008-06-28 14:25
    关注

    建议 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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作