Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton size mystery

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks.
Paul
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all depends on what layout manager you are using.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the behaviour of GridLayout.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic