Can I make Swing JButtons have smaller margins?

后端 未结 2 1989
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-18 15:40

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 tha

相关标签:
2条回答
  • 2021-02-18 16:06

    I believe setMargin is what you're looking for.

    myButton.setMargin(new Insets(0, 0, 0, 0));
    
    0 讨论(0)
  • 2021-02-18 16:10

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

    0 讨论(0)
提交回复
热议问题