Morufu Salawu
Morufu Salawu

Reputation: 185

getWidth() didnt give right panel width when called

I am working on a Java JFrame object and whenever I called the value of my getWidth() and getHeight(), it is always returning more than the value I set for my Panel using the setPreferredSize() function.

Can someone tell me why? Form instance if I declare my Panel to this.setPreferredSize(new Dimension(500,400));

I do get value 520, and 462 whenever I call the getWidth(), and getHeight() respectively.

Upvotes: 0

Views: 94

Answers (1)

Dan D.
Dan D.

Reputation: 32391

The panel is laying inside the JFrame that has a border and a title bar. These pieces increase the size of the JFrame and their size depends on Look and Feel and operating system.

Upvotes: 5

Related Questions