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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器