Java双屏幕应用程序

Java双屏幕应用程序,java,multiple-monitors,Java,Multiple Monitors,在我的应用程序中,我有两个窗口(jframe),一个用于控制,一个用于显示内容(如powerpoint演示模式) 启动应用程序时,如何指定一个窗口在屏幕1中打开,另一个窗口在屏幕2中打开 下面的方法在某种程度上是有效的,但问题是第二个屏幕上的窗口总是最大化,我不希望它被最大化。但连接GraphicsDevice和JFrame的唯一方法似乎是名为setFullScreenWindow的函数 public static void showOnScreen( int screen, JFrame fr

在我的应用程序中,我有两个窗口(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" );
    }
}
publicstaticvoidshowonscreen(intscreen,JFrame)
{
GraphicsEnvironment ge=GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice[]gs=ge.getScreenDevices();
如果(屏幕>-1&&screen0)
{
gs[0].setFullScreenWindow(框架);
}
其他的
{
抛出新的RuntimeException(“未找到屏幕”);
}
}

您可以使用图形设备定义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
}
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[]gs=ge.getScreenDevices();
对于(int j=0;j
您可以使用图形设备定义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
}
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[]gs=ge.getScreenDevices();
对于(int j=0;j
如果屏幕形成一个大型虚拟屏幕,则可以使用具有以下边界的图形配置:

  • 矩形[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);
}

如果屏幕形成一个大虚拟屏幕,则可以使用具有以下边界的图形配置:

  • 矩形[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);
}