每当我单击 button1 时,我都想获得 Jframe 的当前大小。这是我最初在 button1clickevent 中编写的代码,当我单击按钮时,我确实得到了宽度和高度,但是当我更改 Jframe 的大小时,然后再次单击 button1,我得到了与我相同的宽度和高度早点。值不会随时更改。
AppDisplay ap=new AppDisplay(); //class which has got the JFrame
int f12;
f12=ap.getContentPane().getSize().width;
System.out.println(f12+"\n");
f12=ap.getContentPane().getSize().height;
System.out.println(f12);
最佳答案
我认为您引用了错误的 Object
。什么是 AppDisplay
以及为什么需要新实例?
此外,Frame.getSize();
有什么问题?
关于java - 如何在运行时获取 JFrame 的当前尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11712162/