Java GUI多屏幕的窗口设置

本文介绍了两种在JavaGUI中设置多屏幕窗口的方法。第一种使用GraphicsEnvironment获取最大窗口边界并设置窗口大小和位置;第二种通过GraphicsDevice获取屏幕设备,结合Toolkit调整窗口以适应屏幕,排除任务栏区域。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值