Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton and setSize()

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to set up my JButton so that there is minimum marging between the name of the button and it's borders:
|------------------|
| M M |
|<--->Button <---->|
| |
|------------------|
I tried doing:
JButton button = new JButton();
button.setSize(2,2);
But it has no affect on how the JButton looks. What should I do?
thanks,
Alex
 
eric moon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to call setPreferredSize() to get the button to resize. You may also need to call setMinimumSize() depending on the layout manager you are using.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the setMargin method. The setPreferredSize() deals with the entire button not the margin between the edge and the text. The setMargin method takes an Insets as input.
 
Brian Dienes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. setMargin works great for me!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic