Yoda
Yoda

Reputation: 18068

How to get real JPanel Size?

How should I get real JPanel size in JFrame?

Upvotes: 12

Views: 45095

Answers (2)

Garrett Hall
Garrett Hall

Reputation: 30022

The size will be 0,0 until it is displayed because the components and layout are not calculated beforehand.

Upvotes: 22

km1
km1

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

Related Questions