Reputation: 18068
How should I get real JPanel size in JFrame?
Upvotes: 12
Views: 45095
Reputation: 30022
The size will be 0,0
until it is displayed because the components and layout are not calculated beforehand.
Upvotes: 22
Reputation: 2443
thePanel.getSize();
This returns the Dimension.
I sometimes add a ComponentListener to show the dimension when the panel is resized.
EDIT: If you want the size of the content pane of the JFrame then
theFrame.getContentPane().getSize();
Upvotes: 9