i have a JFrame that contain a JButton when JFrame shows up, user will resize JFrame, then click the JButton which will do:
System.out.print("actual size now = "+JFrame.getsize");
but the size will not result the actual size of JFrame on the screen.
The size still wrong when i use:
-
JFrame.getSize -
JFrame.getPrefferedSize -
JFrame.getMinimumSize -
JFrame.getMaximumSize -
JFrame.getBounds -
JFrame.getHeight&getwidth
what should i do?
Thanks a lot for any kind of help
The size you are getting is the size of the
JFrames contentPane and the size of theInsets added. Simply callJFrame#getInsets()and subtract them from theJFrames width and height which you can get viaJFrame#getSize().Here is an example:
output: