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
- 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
Use a smaller font ?
you could use a narrower border but that doesn't save you much.
ASKER
exactly. how do i change the border's size/insets without really knowing the border's type ? well button.getInsets() or button.getBorder().getBord erInsets() 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.getIn sets());
b.getInsets().left = 0;
b.getInsets().right = 0;
System.out.println(b.getIn sets());
... nothin
And I'd like this to work on all L&Fs :)
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.getIn
b.getInsets().left = 0;
b.getInsets().right = 0;
System.out.println(b.getIn
... 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
hehe, good luck!!
Tim