How to deploy a JFrame in multiple monitor configuration

北慕城南 提交于 2019-12-12 01:55:25

问题


I'd like to build an app that has 2 windows. The first one should always be in the first monitor, and can't be maximized. The second one should be launched in second monitor (a perfect example is like PowerPoint's presentation mode), is running "on top" of any other applications' window, and always maximized. This window is launched using a listener given to the first window. Note that these "monitors" may be LCD projectors used in presentations, or real desktop computer monitors.

I know that there exists GraphicsEnvironment API, and we can know whether our monitor configuration is treated as a single monitor, or treated separately. But, I don't know how to implement it. I mean, since screen configurations can be treated differently depending on their graphic cards, how do we validate them?

For example, if there are 3 monitors treated as a single monitor with large resolution, then perhaps we can set a coordinate x0 for second window as : total_width * 2 / 3. But, what if it is treated as seperate monitors..?

Thanks.


回答1:


@Zecas : Yes, it worked out well. Sorry for not posting the answer here. I totally forgot. So, the solution is exactly as what ShivanDragon has stated, we can get each monitor individually by obtaining our GraphicsEnvironment first, and then get our screen devices from the Environment:

GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();

After that, just use:

gs[_screen_index].setFullSCreenWindow(_frame)


来源:https://stackoverflow.com/questions/7688409/how-to-deploy-a-jframe-in-multiple-monitor-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!