通过java确定窗口显示数量和/或布局 [英] Determine windows display number and/or layout via java

查看:372
本文介绍了通过java确定窗口显示数量和/或布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全屏java应用程序,它将在Windows 7计算机上的8监视器数字标牌类型显示器上运行。我需要能够在特定的物理监视器上显示内容。理想情况下,我希望在显示属性 - >设置中按顺序1-8显示显示,但是许多拔出/插入和重新排序的尝试都无法通过显示属性 - >设置以任何确定的顺序显示物理监视器。我可以对它们进行重新排序,但是当我的java程序在显示器上检索信息时,窗口中没有配置它们的布局/顺序。

I have a fullscreen java app that will run on an 8 monitor digital signage type display on a Windows 7 machine. I need to be able to display content on specific physical monitors. Ideally I would like the displays ordered 1-8 in Display Properties -> Settings, however many attempts of unplugging/plugging in and reordering have failed to get the physical monitors to appear in any deterministic order via the Display Properties->Settings. I can reorder them fine, but when my java program retrieves information on the displays it is not in the layout/order that windows has them configured.

GraphicsEnvironment ID返回字符串等作为Device0和Device1,但这些与显示属性中显示的Windows显示编号不匹配。例如,如果布局是7,4,1,2,3,4,5,6我仍然返回Device0,Device1 ...其中Device0对应于识别的屏幕1(不是7,这是左边的第一个屏幕) )。有没有办法查询操作系统以确定显示器所处的布局和/或在特定物理监视器上显示全屏的其他技术?

GraphicsEnvironment ID returns Strings such as Device0 and Device1, but these do not match the Windows Display numbering as seen in the Display properties. For instance if the layout is 7,4,1,2,3,4,5,6 I still get back Device0, Device1... in which Device0 corresponds to identified screen 1 (not 7 which is the first screen on the left). Is there a way to query the OS to determine what layout the displays are in and/or some other technique to display fullscreen on a specific physical monitor?

推荐答案

您可以获取相对于大虚拟桌面的屏幕范围:

You can get the bounds of the screens relative to the big virtual desktop:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
for (GraphicsDevice gd : ge.getScreenDevices()) {
    Rectangle bounds = gd.getDefaultConfiguration().getBounds();
    System.out.println(bounds.toString());
}

我的设置给出:

java.awt.Rectangle[x=0,y=0,width=1280,height=1024]
java.awt.Rectangle[x=1280,y=304,width=1280,height=720]

您可以使用此信息确定订单。例如。如果您完全确定您的显示器处于一个漂亮的网格中,您可以在右上方的显示器上全屏显示如下:

You can use this information to determine their order. E.g. if you are absolutely sure that your monitors are in a nice grid you can go fullscreen on the upper right monitor like this:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gdUpperRight = null;
Rectangle bUpperRight = null;
for (GraphicsDevice gd : ge.getScreenDevices()) {
    Rectangle b = gd.getDefaultConfiguration().getBounds();
    if (bUpperRight == null || b.x > bUpperRight.x || b.y > bUpperRight.y) {
        bUpperRight = b;
        gdUpperRight = gd;
    }
}

gdUpperRight.setFullScreenWindow(myFrame);

这篇关于通过java确定窗口显示数量和/或布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆