1

在我的应用程序中,我有 2 个窗口(jframe),一个用于控制,一个用于显示内容(如 powerpoint 演示模式)。

如何指定在屏幕编号中打开一个窗口。1,另一个在屏幕编号中打开。2 我什么时候开始申请?

下面的方法以某种方式起作用,但问题是第二个屏幕上的窗口总是最大化,我不希望它被最大化。但似乎连接 GraphicsDevice 和 JFrame 的唯一方法是调用 setFullScreenWindow 的函数。

public static void showOnScreen( int screen, JFrame frame )
{
    GraphicsEnvironment ge = GraphicsEnvironment
        .getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    if( screen > -1 && screen < gs.length )
    {
        gs[screen].setFullScreenWindow( frame );
    }
    else if( gs.length > 0 )
    {
        gs[0].setFullScreenWindow( frame );
    }
    else
    {
        throw new RuntimeException( "No Screens Found" );
    }
}
4

2 回答 2

3

您可以使用 GraphicsDevice 定义 JFrame。

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

for (int j = 0; j < gs.length; j++) { 
    JFrame f = new JFrame(gs[j].getDefaultConfiguration());
    // Rest of the code
}
于 2013-05-29T16:26:27.697 回答
1

如果屏幕形成一个大虚拟屏幕,则可以具有具有以下界限的 GraphicsConfigurations:

  • 矩形[x=-1280,y=74,宽度=1280,高度=1024]
  • 矩形[x=0,y=0,宽度=1920,高度=1080]
  • 矩形[x=1920,y=0,宽度=1920,高度=1080]

这些是并排的 3 台显示器。所以:

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
for (GraphicsDevice gd : gds) {
    int x = gd.getDefaultConfiguration().getBounds().x;
    int y = gd.getDefaultConfiguration().getBounds().y;
    JFrame frame = new NewJFrame();
    frame.setLocation(x, y);
    frame.setVisible(true);
}
于 2013-05-29T16:47:00.787 回答