Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make Swing JButtons have smaller margins?

I prefer buttons with minimal margins, about as wide as their text caption. Is there a way to achieve that in a JButton in Swing?

What I am seeing in practice now is that even if I try to use setMaximumSize() and similar, it just ends up eating the text caption, cutting it off to the right. But it does not reduce the margins.

like image 410
EndangeringSpecies Avatar asked Dec 23 '09 18:12

EndangeringSpecies


2 Answers

I believe setMargin is what you're looking for.

myButton.setMargin(new Insets(0, 0, 0, 0));
like image 51
Michael Myers Avatar answered Nov 09 '22 09:11

Michael Myers


Worth noting you can make the values for Insets -ve. This makes things even more compact and if done carefully doesn't look unpleasant.

like image 33
UnixNerd Avatar answered Nov 09 '22 08:11

UnixNerd