java&全屏超过多个显示器 [英] java & fullscreen over multiple monitors
问题描述
我的Java应用程序的片段:
A snippet from my Java application:
JFrame f = new JFrame();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
gd.setFullScreenWindow(f);
所以它的作用是让它自动全屏。现在奇怪的是程序是全屏的,但只在一台显示器上!
例如我有一个带有两个屏幕的Windows Vista系统,它们组合在一个桌面上。
怎么办自动让它全屏显示所有显示器?
So what it does is make it self fullscreen. Now the odd thing is that the program is fullscreen but only on one monitor! E.g. I have a windows vista system with two screens that are combined in one desktop. What to do automatically let it go fullscreen over all monitors?
好的我试过了:
import java.awt.image.ColorModel;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
class grdevs
{
public static void main(String [] args)
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for(GraphicsDevice curGs : gs)
{
GraphicsConfiguration[] gc = curGs.getConfigurations();
for(GraphicsConfiguration curGc : gc)
{
Rectangle bounds = curGc.getBounds();
ColorModel cm = curGc.getColorModel();
System.out.println("" + bounds.getX() + "," + bounds.getY() + " " + bounds.getWidth() + "x" + bounds.getHeight() + " " + cm);
}
}
}
}
但是它给出:
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
0.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
1024.0,0.0 1024.0x768.0 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
例如,我希望设备能够合成2048x768,因为它们合二为一(我点击了扩展桌面)。
E.g I would expect a device capable of 2048x768 as they are combined in one (I clicked on "extend desktop").
推荐答案
您可以尝试:
int width = 0;
int height = 0;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for (GraphicsDevice curGs : gs)
{
DisplayMode mode = curGs.getDisplayMode();
width += mode.getWidth();
height = mode.getHeight();
}
这应计算多个屏幕的总宽度。显然它只支持上面形式的水平对齐屏幕 - 您必须分析图形配置的边界以处理其他显示器对齐(取决于您想要制作它的防弹方式)。
This should calculate the total width of multiple screens. Obviously it only supports horizontally aligned screens in the form above - you'd have to analyse the bounds of the graphics configurations to handle other monitor alignments (depends how bulletproof you want to make it).
编辑:然后设置框架的大小: f.setSize(宽度,高度);
And then set the size of your frame: f.setSize(width, height);
这篇关于java&全屏超过多个显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!