在Java中获取JFrame窗口大小信息
要获取JFrame窗口大小信息,可以使用以下命令-
environment.getMaximumWindowBounds();
对于屏幕尺寸-
config.getBounds()
对于框架尺寸-
frame.getSize());
以下是获取JFrame窗口大小信息的示例-
示例
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.JFrame;
public class SwingDemo {
public static void main(String[] args) {
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle bounds = environment.getMaximumWindowBounds();
System.out.println("Screen Bounds = " + bounds);
GraphicsDevice device = environment.getDefaultScreenDevice();
GraphicsConfiguration config = device.getDefaultConfiguration();
System.out.println("Screen Size = " + config.getBounds());
JFrame frame = new JFrame("Frame Info");
frame.setSize(500, 300); frame.setVisible(true);
System.out.println("Frame Size = " + frame.getSize());
}
}输出结果
Screen Bounds = java.awt.Rectangle[x=0,y=0,width=1366,height=728] Screen Size = java.awt.Rectangle[x=0,y=0,width=1366,height=768] Frame Size = java.awt.Dimension[width=500,height=300]
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短