This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JButton size mystery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton size mystery" Watch "JButton size mystery" New topic

JButton size mystery

Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
When I do getSize() of a JButton with text that I've just added to a JPanel it gives me a Dimension width and height of 0, 0. Once I dynamically change the text on the button the Dimensions become different - such as 222, 174. Why is this?
Also, is there a way to maintain the original size of the JButtons when the text on them dynamically changes but still allow the size to change as you drag the frame? When I do this now, my buttons (16 of them sitting on a panel in GridLayout) all change to suit the size of the one button that has the longest text.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
It all depends on what layout manager you are using.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
That is the behaviour of GridLayout.
subject: JButton size mystery
Similar Threads
JButton with ImageIcon Size Problem
Problems positioning buttons in GridBagLayout
jButton revalidate, updateUI, repaint does not working
Hard coding component size in GUI?
How to change the button size dynamically ?