不介意Window Insets的使用,但更注意ScreenInsets的使用,它在本地保存为Insets insets;我打印 insets.bottom,并且对于每个监视器,任务栏高度都会显示,即使任务栏仅位于第一台监视器上。
我的第二台显示器上的显示器插图都应该为零,但它的作用就像任务栏位于两个显示器上一样。在窗口当前所在的监视器中将窗口设置为全尺寸,除了它为任务栏留出空间,无论在哪个监视器中使用它。
根据我对 Toolkit.getScreenInsets(GraphicsConfiguration) 的理解,它应该为您传入的特定 GraphicsConfiguration 返回正确的插图,但我传入每个 GraphicsDevice 的 GraphicsConfiguration 并得到相同的结果。
JFrame window;
public void setSizeToFullScreen()
{
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screenDevices=ge.getScreenDevices();
Point p=window.getLocationOnScreen();
for(int i=0;i<screenDevices.length;i++)
{
Rectangle2D b=screenDevices[i].getDefaultConfiguration().getBounds();
if(SMath.getMath().doesRectangleContainPoint(b.getX(), b.getY(), b.getWidth(), b.getHeight(), p.getX(),p.getY()))
{
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(screenDevices[i].getDefaultConfiguration());
System.out.println("Monitor: "+i+": task bar height: "+insets.bottom);
this.setSize(b.getWidth()+1 -(insets.right+insets.left)-(this.window.getInsets().left+this.window.getInsets().right), b.getHeight()+1-(insets.top+insets.bottom)-(this.window.getInsets().top+this.window.getInsets().bottom));
this.setLocation(b.getX()+insets.left+window.getInsets().left, b.getY()+insets.top+window.getInsets().top);
return;
}
}
}
我的问题是,在 Java 中,我们如何才能确定哪个监视器实际上有任务栏,或者更好的问题是,我们如何才能在 Java 中为每个监视器获取正确的监视器插图。