• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

button size/insets

I have a button with only one character as text. I want this button as small as possible. How can I change its insets ?

- button.getInsets().set(0, 0, 0, 0) doesn't seem to work
- if I do button.setBorder(null) - I get the smallest possible size which is what I want, but I lose, of course, the button's nice look

Thanks
0
hapciu
Asked:
hapciu
  • 2
  • 2
  • 2
  • +1
1 Solution
 
CEHJCommented:
Use a smaller font ?
0
 
objectsCommented:
you could use a narrower border but that doesn't save you much.
0
 
hapciuAuthor Commented:
exactly. how do i change the border's size/insets without really knowing the border's type ? well button.getInsets() or button.getBorder().getBorderInsets() and change those you say... but it don't work.

Just try this:
JButton b = new JButton("I");
// add the button to your favourite container and see how excessively wide it is :)
System.out.println(b.getInsets());
b.getInsets().left = 0;
b.getInsets().right = 0;
System.out.println(b.getInsets());

... nothin


 And I'd like this to work on all L&Fs :)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
objectsCommented:
you don't need to know the border size, you only need to set it to whatever border you want.
0
 
TimYatesCommented:
Insets margins = new Insets( 0, 0, 0, 0 ) ;
JButton b = new JButton("I");
b.setMargin( margins ) ;

?
0
 
hapciuAuthor Commented:

I found out myself just now - one trick is to extend Jbutton and overwrite getInsets() to return what you want - in my case new Insets(2, 2, 2, 2)

TimYates' solution is shorter though - I should've searched the Javadoc more careful (now where's that "I'm ashamed" emoticon ?)
0
 
TimYatesCommented:
:-)

hehe, good luck!!

Tim
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now