系统支持双屏显示,两个显示器设置为不同的分辨率,一个为1024×768(32真彩色)一个为1600×1200(256色),程序需要双屏显示,其中主程序在第一个屏幕,在程序中通过命令行外部调用另一个程序,并且要显示到第二个屏幕上,请问如何实现?或者我如何在子程序中设置其显示位置为第二个显示器?

解决方案 »

  1.   

    去看一下java.awt.GraphicsDevice类的API文档,里面有示例代码
      

  2.   

    ToolKit类的getScreenSize()方法只能得到主显示屏幕的显示尺寸,要得到其他屏幕的显示尺寸需要用到GraphicsConfiguration类和GraphicsDevice类,具体方法自己去查文档吧。
      

  3.   

    JFrame frame = new JFrame();
    ....................
          // Center of the screen.
          Rectangle screenRect = frame.getGraphicsConfiguration().getBounds();
          Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());       int centerWidth = screenRect.width < MainFrame.newContentPane.getSize().width ?
                   screenRect.x :
                   screenRect.x + screenRect.width/2 - frame.getSize().width/2;
           int centerHeight = screenRect.height < frame.getSize().height ?
                   screenRect.y :
                   screenRect.y + screenRect.height/2 - frame.getSize().height/2;       centerHeight = centerHeight < screenInsets.top ?
                   screenInsets.top : centerHeight;       //
           centerWidth = (screenRect.width - 800)/2;
           centerHeight = (screenRect.height - 700)/2;       centerHeight = centerHeight < screenInsets.top ?
                   screenInsets.top : centerHeight;
           frame.setLocation(centerWidth, centerHeight);