Java GUI多屏幕的窗口設置

Java GUI多屏幕的窗口設置

WorkbenchWindow window = (WorkbenchWindow) getWindowConfigurer().getWindow();
	Shell shell  = window.getShell();
	Rectangle screenSize = Display.getDefault().getClientArea();
	int sW = screenSize.width;
	int sH = screenSize.height;
    shell.setSize(new Point(sW, sH));

第一種方式

GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
	//獲取除去任務欄的剩餘區域
	java.awt.Rectangle maximumWindowBounds = graphicsEnvironment.getMaximumWindowBounds();
	//設置配載軟件窗口大小和位置
	shell.setBounds(maximumWindowBounds.x, maximumWindowBounds.y,   	maximumWindowBounds.width, maximumWindowBounds.height);

第二種方式

GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
	GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices();
	//這種方式獲取的是整個顯示屏幕的大小,包含了任務欄的高度。
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsDevices[0].getDefaultConfiguration());
	//獲取除去任務欄的剩餘區域
	Rectangle maximumWindowBounds = new Rectangle(screenInsets.left, screenInsets.top, 
			screenSize.width - screenInsets.left - screenInsets.right, 
			screenSize.height - screenInsets.top - screenInsets.bottom);
	shell.setBounds(maximumWindowBounds);