Mar*_*erg 3 java windows multiple-monitors toolkit jframe
我有主应用程序JFrame窗口,它可以包含不同的组件.当用户选择可编辑的文本字段时,我打开一个自己实现的OnScreenKeyboard.OSK也是一个JFrame窗口.
当用户将主窗口拖动到另一台监视器时,OSK也应显示在同一监视器上.为此,我必须检测显示器,显示主JFrame.
我试着找到一个方法
Toolkit.getDefaultToolkit()
Run Code Online (Sandbox Code Playgroud)
但是找不到东西.
你知道我怎么能检测显示JFrame的显示器吗?
Java-Version 1.4 Windows XP
谢谢
如果所有可用监视器的解决方案都相同,请回答.
对于AWT:
每个Control都有getMonitor()方法,从中可以计算出屏幕位置得到的方法:
Monitor widgetMonitor = mTextWidget.getMonitor();
Rectangle monitorRect = widgetMonitor.getBounds();
if(monitorRect.x < 0){
// shown in left monitor, starting from the main monitor
}
if(monitorRect.x > monitorRect.width){
// shown in right monitor, starting from the main monitor
}
Run Code Online (Sandbox Code Playgroud)
对于SWT:
这只是我的原始代码的一部分.你应该问一下返回值是否为null这样的东西!
int monitorWidth = 0;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screenDevices = ge.getScreenDevices();
if(screenDevices.length > 0){
monitorWidth = screenDevices[0].getDisplayMode().getWidth();
}
Point ownerLocationOnScreen = owner.getLocationOnScreen();
int screenMovingX = 0;
if(ownerLocationOnScreen.x < 0){
screenMovingX = -monitorWidth;
}
if(ownerLocationOnScreen.x > monitorWidth){
screenMovingX = monitorWidth;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3589 次 |
| 最近记录: |