jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Setting Height and Width of JButtons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Setting Height and Width of JButtons" Watch "Setting Height and Width of JButtons" New topic
Author

Setting Height and Width of JButtons

Graham Spice
Greenhorn

Joined: Nov 01, 2001
Posts: 5
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

Joined: Jul 23, 2001
Posts: 91
Looks like layout manager is over riding your settings for the isze of JButton.
Try to put this statement.
setLayoutManager(null);


Journey is as important as the Destination.<br /> <br />PMP, SCJP, SCJD, SCEA (Part 1), SCMAD, SCDJWS
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
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

Joined: Nov 01, 2001
Posts: 5
Thanks for the responses,
I'll give them a try...
Graham
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting Height and Width of JButtons