This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Height and Width of JButtons

 
Graham Spice
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm trying to set the Height and Width of JButtons but for the life of me I can't get it going.
I've tried
button1.setSize(100,100);
but it doesn't seem to work.
Any clues?
Thanks.
 
Suresh Bansal
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like layout manager is over riding your settings for the isze of JButton.
Try to put this statement.
setLayoutManager(null);
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't set the layout to null. Set the size using setMinimumSize(), setPreferredSize() methods inherited from JComponent. It takes a Dimension as parameter.
So the code would look like this:
button.setPreferredSize(new Dimension(100, 50));
I have yet to find setting the layout to null to be needed.
 
Graham Spice
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the responses,
I'll give them a try...
Graham
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic