如何设置默认启动显示?

时间:2015-02-22 23:16:39

标签: java swing

下面的输出表明,无论我从哪个物理显示器启动此应用程序(请参阅下面的代码),它启动的默认screenCGraphicsDevice[screen=0]

如何调整Window属性,以便windows[0].getGraphicsConfiguration()运行CGraphicsDevice[screen=1]而不是CGraphicsDevice[screen=0]

输出

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]

GraphicsConfig.java

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]);
      }
   }
}

0 个答案:

没有答案