문제

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.

도움이 되었습니까?

해결책

I believe setMargin is what you're looking for.

myButton.setMargin(new Insets(0, 0, 0, 0));

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top