在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 教师闺蜜祝福语简短