Link to home
Start Free TrialLog in
Avatar of hapciu
hapciu

asked on

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Use a smaller font ?
you could use a narrower border but that doesn't save you much.
Avatar of hapciu
hapciu

ASKER

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 :)
you don't need to know the border size, you only need to set it to whatever border you want.
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hapciu

ASKER


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 ?)
:-)

hehe, good luck!!

Tim