• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton & setSize

 
Matthew Bailey
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They don't take an int, they take a Dimension
 
Maneesh Godbole
Saloon Keeper
Posts: 10968
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matthew Bailey
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So if I put the button into a panel I can change the size of it?
 
Maneesh Godbole
Saloon Keeper
Posts: 10968
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use setPrefferedSize().
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic