SWT Java: How to prevent window from resizing?

后端 未结 3 1162
忘掉有多难
忘掉有多难 2020-12-17 21:28

I want to disable resizing of window. Any ideas?

3条回答
  •  [愿得一人]
    2020-12-17 22:01

    You can control the furniture when you declare the shell. I think this example does what you want;

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Event;
    import org.eclipse.swt.widgets.Listener;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.swt.widgets.Text;
    
    public class FixedWindow {
        public static void main(String[] args) {
            Display display = new Display();
    
            //final Shell shell = new Shell(display); //defaults
            //final Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX); //can be maximised
            final Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN ); // fixed but can be minimised
            //final Shell shell = new Shell(display,  SWT.TITLE ); // fixed, uncloseable, unminimisable can only be removed by OS killing JVM.
    
            Rectangle boundRect = new Rectangle(0, 0, 1024, 768);
            shell.setBounds(boundRect);
            Rectangle boundInternal = shell.getClientArea();
    
            shell.setText("Fixed size SWT Window.");
    
            shell.open();
    
            final Text text = new Text(shell, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    
            text.setEditable(true);
            text.setEnabled(true);
            text.setText("Oh help!");
            text.setBounds(boundInternal);
    
    
            while (!shell.isDisposed()) {
    
                if (!display.readAndDispatch())
                    display.sleep();
            }
            display.dispose();
        }
    }
    

提交回复
热议问题