如何在不同分辨率的双屏显示系统指定窗口的位置 系统支持双屏显示,两个显示器设置为不同的分辨率,一个为1024×768(32真彩色)一个为1600×1200(256色),程序需要双屏显示,其中主程序在第一个屏幕,在程序中通过命令行外部调用另一个程序,并且要显示到第二个屏幕上,请问如何实现?或者我如何在子程序中设置其显示位置为第二个显示器? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 去看一下java.awt.GraphicsDevice类的API文档,里面有示例代码 ToolKit类的getScreenSize()方法只能得到主显示屏幕的显示尺寸,要得到其他屏幕的显示尺寸需要用到GraphicsConfiguration类和GraphicsDevice类,具体方法自己去查文档吧。 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); java下面哪个是正确的! jni技术高手:java调用c++写的des加密dll程序,知道如何实现吗? 需要用java swing实现一个文本编辑器,有几个问题 请教:为什么一个窗体单独可以运行,一旦从主窗体中进行调用就不能运行 java各种处理时间的方法 初学java ,做练习时发现练习里面涉及具体算法的问题几乎没有,这是为什么? 程序运行时总是显示有异常,求修改 关于j2sdk1.4和oracle9i的连接 初学者,有几个问题 新人求问 关于日期的问题,总会出现延后时间。 子类对象调用覆盖的方法? 求用JAVA编写的远程屏幕监控程序源代码
....................
// 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);