aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JButton & setSize Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton & setSize" Watch "JButton & setSize" New topic
Author

JButton & setSize

Matthew Bailey
Greenhorn

Joined: Jan 29, 2009
Posts: 6
Why doesn't setSize() do anything? I have a button but it takes up the size of the whole frame and I have tried using setSize() to make it smaller but it does absolutley nothing. I've read elsewhere that instead of setSize() you should use setPreferredSize or setMinimumSize() but they take (int dimension) as a parameterr and I have no idea what the value should be because every number I have tried just seems to give an error and doesn't work.

Please help.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
They don't take an int, they take a Dimension
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

From your post, looks like you are adding the button directly to the frame.
The frame's content pane defaults to BorderLayout. That is what's causing your button to fill up the frame.

You got two options
1) Set the content pane's layout to flow layout.
2) Create a panel ( defaults to flow layout). Add your button to the panel and then add the panel to the content pane.

Swing related. Moving.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Matthew Bailey
Greenhorn

Joined: Jan 29, 2009
Posts: 6
So if I put the button into a panel I can change the size of it?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

If you use setPrefferedSize().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JButton & setSize