Windows不支持myFrame.setExtendedState(JFrame.MAXIMIZED_VERT);
。
所以我试图获得屏幕尺寸并使JFrames的高度与屏幕高度一样大。但它涵盖了Windows任务栏。
还有其他方法可以最大化我的JFrame吗?
谢谢,
esanits
答案 0 :(得分:3)
尝试一下,伙计:
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(t.getGraphicsConfiguration());
int taskHeight=screenInsets.bottom;
System.out.println(taskHeight);
答案 1 :(得分:1)
以下是获取窗口和框架基本信息的一种方法:
import java.awt.*;
import javax.swing.*;
public class FrameInfo
{
public static void main(String[] args)
{
String laf = "javax.swing.plaf.metal.MetalLookAndFeel";
// laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
// laf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
// try { UIManager.setLookAndFeel( laf ); }
// catch (Exception e) { System.out.println(e); }
// JFrame.setDefaultLookAndFeelDecorated(true);
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = env.getMaximumWindowBounds();
System.out.println("Screen Bounds: " + bounds );
GraphicsDevice screen = env.getDefaultScreenDevice();
GraphicsConfiguration config = screen.getDefaultConfiguration();
System.out.println("Screen Size : " + config.getBounds());
System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
JFrame frame = new JFrame("Frame Info");
System.out.println("Frame Insets : " + frame.getInsets() );
frame.setSize(200, 200);
// frame.pack();
System.out.println("Frame Insets : " + frame.getInsets() );
frame.setVisible( true );
System.out.println("Frame Size : " + frame.getSize() );
System.out.println("Frame Insets : " + frame.getInsets() );
System.out.println("Content Size : " + frame.getContentPane().getSize() );
}
}
答案 2 :(得分:0)
我不确定这是不是最好的方式,但它对我有用......
Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(mainScreen.getGraphicsConfiguration());
int taskHeight=screenInsets.bottom;
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
mainScreen.setSize(d.width/2, d.height - taskHeight);
mainScreen.setLocation(d.width/2, 0);