Ben*_*ann 77
java.awt.Toolkit.getDefaultToolkit().getScreenSize()
Run Code Online (Sandbox Code Playgroud)
Law*_*Dol 18
以下是我使用的两种方法,它们考虑了多个监视器和任务栏插件.如果您不需要单独使用这两种方法,当然可以避免两次获取图形配置.
static public Rectangle getScreenBounds(Window wnd) {
Rectangle sb;
Insets si=getScreenInsets(wnd);
if(wnd==null) {
sb=GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration()
.getBounds();
}
else {
sb=wnd
.getGraphicsConfiguration()
.getBounds();
}
sb.x +=si.left;
sb.y +=si.top;
sb.width -=si.left+si.right;
sb.height-=si.top+si.bottom;
return sb;
}
static public Insets getScreenInsets(Window wnd) {
Insets si;
if(wnd==null) {
si=Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration());
}
else {
si=wnd.getToolkit().getScreenInsets(wnd.getGraphicsConfiguration());
}
return si;
}
Run Code Online (Sandbox Code Playgroud)
Pac*_*ier 16
工作区域是显示器的桌面区域,不包括任务栏,停靠窗口和停靠工具栏.
如果你想要的是屏幕的"工作区域",请使用:
public static int GetScreenWorkingWidth() {
return java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width;
}
public static int GetScreenWorkingHeight() {
return java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height;
}
Run Code Online (Sandbox Code Playgroud)
以下代码应该这样做(没试过):
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
gd.getDefaultConfiguration().getBounds().getWidth();
Run Code Online (Sandbox Code Playgroud)
编辑:
对于多个监视器,您应该使用以下代码(取自javadocjava.awt.GraphicsConfiguration
:
Rectangle virtualBounds = new Rectangle();
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsDevice[] gs =
ge.getScreenDevices();
for (int j = 0; j < gs.length; j++) {
GraphicsDevice gd = gs[j];
GraphicsConfiguration[] gc =
gd.getConfigurations();
for (int i=0; i < gc.length; i++) {
virtualBounds =
virtualBounds.union(gc[i].getBounds());
}
}
Run Code Online (Sandbox Code Playgroud)
Toolkit有许多类可以帮助:
我们最终使用1和2来计算可用的最大窗口大小.要获得相关的GraphicsConfiguration,我们使用
GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDefaultConfiguration();
Run Code Online (Sandbox Code Playgroud)
但可能有更智能的多显示器解决方案.
归档时间: |
|
查看次数: |
69099 次 |
最近记录: |