When is the size of the JComponent is calculated? After being shown in the screen or before that?
if I send .getSize() message before .setVisible(true), would it give me the right answer?
Thanks
When is the size of the JComponent is calculated? After being shown in the
Share
I sometimes check the sizes of my components when debugging to find out why I can’t see them for instance. In most cases, the sizes will be realized when the GUI has been rendered. This can occur when
pack()orsetVisible(true)has called on the top-level window. My usual sequence of method calls is to callpack()first as this tells the layout managers to lay out the components that they are responsible for, and sets the sizes of the components and the GUI, then callsetLocationRelativeTo(null)to center my GUI, then callsetVisible(true)to display it.