设置JFace的Dialog样式

经常性的,自己设计的对话框无法改变大小,没有最大化最小化按钮,等等.在哪里设置这些属性呢?

JFace的Dialog继承于Window类,该类中有一方法,设置Shell的样式.

setShellStyle

protected void setShellStyle(int newShellStyle)
Sets the shell style bits. This method has no effect after the shell is created.

The shell style bits are used by the framework method createShell when creating this window's shell.

Parameters:
newShellStyle - the new shell style bits


在Dialog的构造函数中调用该方法,即可更改Dialog的样式.下为一例:

import  org.eclipse.jface.dialogs.Dialog;
import  org.eclipse.swt.SWT;
import  org.eclipse.swt.browser.Browser;
import  org.eclipse.swt.layout.GridData;
import  org.eclipse.swt.widgets.Composite;
import  org.eclipse.swt.widgets.Control;
import  org.eclipse.swt.widgets.Shell;

public   class  BrowserDialog  extends  Dialog  {

    
private  String url;

    
public  BrowserDialog(Shell parent, String url)  {
        
super (parent);
        setShellStyle(getShellStyle() 
|  SWT.RESIZE  |  SWT.MAX);
        
this .url  =  url;
    }


    
protected  Control createContents(Composite parent)  {
        Browser browser 
=   new  Browser(parent, SWT.NONE);
        browser.setUrl(url);
        GridData gd 
=   new  GridData(GridData.FILL_BOTH);
        gd.minimumWidth 
=   600 ;
        gd.minimumHeight 
=   400 ;
        browser.setLayoutData(gd);
        
return  browser;
    }

}

import  org.eclipse.swt.SWT;
import  org.eclipse.swt.widgets.Display;
import  org.eclipse.swt.widgets.Shell;

public   class  TestDialog  {

    
public   static   void  main(String[] args)  {

        
final  Shell shell  =   new  Shell(SWT.DIALOG_TRIM  |  SWT.RESIZE  |  SWT.MIN  |  SWT.MAX);
        
final  Display display  =  shell.getDisplay();

        String path 
=   " C:/Temp/log.html " ;
        BrowserDialog dlg 
=   new  BrowserDialog(shell, path);
        dlg.open();

        
while  ( ! shell.isDisposed())  {
            
if  ( ! display.readAndDispatch())  {
                display.sleep();
            }

        }


    }

}

你可能感兴趣的:(设置JFace的Dialog样式)