Setting size of inner region of Java SWT shell window

后端 未结 3 1655
无人共我
无人共我 2021-01-21 12:56

In a Java SWT shell window, how do I set its inner size than its whole window frame size?

For instance, if I use shell.setSize(300, 250) this would make the whole window

3条回答
  •  一个人的身影
    2021-01-21 13:15

    import org.eclipse.swt.SWT;
    import org.eclipse.swt.graphics.*;
    import org.eclipse.swt.widgets.*;
    
    public class SWTClientAreaTest
    {
        Display display;
        Shell shell;
        final int DESIRED_CLIENT_AREA_WIDTH = 300;
        final int DESIRED_CLIENT_AREA_HEIGHT = 200;
    
        void render()
        {
            display = Display.getDefault();
            shell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER);
    
            Point shell_size = shell.getSize();
            Rectangle client_area = shell.getClientArea();
    
            shell.setSize
            (
                DESIRED_CLIENT_AREA_WIDTH + shell_size.x - client_area.width,
                DESIRED_CLIENT_AREA_HEIGHT + shell_size.y - client_area.height
            );
    
            shell.open();
    
            while (!shell.isDisposed()) 
            {
                if (!display.readAndDispatch()) 
                {
                    display.sleep();
                }
            }
    
            display.dispose();
        }
    
        public static void main(String[] args)
        {
            SWTClientAreaTest appl = new SWTClientAreaTest();
            appl.render();
        }
    }
    

提交回复
热议问题