Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何设置默认启动显示?_Java_Swing - Fatal编程技术网

Java 如何设置默认启动显示?

Java 如何设置默认启动显示?,java,swing,Java,Swing,下面的输出表明,无论我从两个物理显示器中的哪一个启动此应用程序,请参见下面的代码,它启动到的默认屏幕是CGraphicsDevice[screen=0] 如何调整窗口属性以使运行windows[0].getGraphicsConfiguration返回CGraphicsDevice[screen=1]而不是CGraphicsDevice[screen=0] 输出 GraphicsConfig.java 更改帧的位置很容易,问题在于确定所需的信息,以确定用于启动应用程序的屏幕。请记住,您的应用程序

下面的输出表明,无论我从两个物理显示器中的哪一个启动此应用程序,请参见下面的代码,它启动到的默认屏幕是CGraphicsDevice[screen=0]

如何调整窗口属性以使运行windows[0].getGraphicsConfiguration返回CGraphicsDevice[screen=1]而不是CGraphicsDevice[screen=0]

输出

GraphicsConfig.java


更改帧的位置很容易,问题在于确定所需的信息,以确定用于启动应用程序的屏幕。请记住,您的应用程序可能不是由用户双击Jar启动的,它可能来自快捷方式、开始菜单或其他系统驱动的事件……这很好。老实说,这是写给我的。有时,我会在每个屏幕上启动多个副本,希望应用程序在IDE中运行时出现在显示屏上。
Window 0: 
apple.awt.CGraphicsConfig@692a3722[dev=CGraphicsDevice[screen=0],pixfmt=0]

Default output device: 
CGraphicsDevice[screen=0]

Connected Displays:
Display 0: CGraphicsDevice[screen=0]
Display 1: CGraphicsDevice[screen=1]
public class GraphicsConfig {
   public static void main(String args[]) {
      JFrame f = new JFrame("Test");
      f.setContentPane(new OkcView().panel1);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.pack();
      // f.setVisible(true);

      Window[] windows = Window.getWindows();
      for (int i = 0; i < windows.length; i++) {
         System.out.println("Window " + i + ": \n" 
                            + windows[i].getGraphicsConfiguration() 
                            + "\n");
      }
      GraphicsConfiguration config = windows[0].getGraphicsConfiguration();
      System.out.println("Default output device: \n" 
                         + config.getDevice() 
                         + "\n");

      GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] allScreens = env.getScreenDevices();
      System.out.println("Connected Displays:");

      for (int i = 0; i < allScreens.length; i++) {
         System.out.println("Display " + i + ": " + allScreens[i]);
      }
   }
}