Java swing - create the smallest button

Hi
When I create a button in a swing, it adds a border around my text, thereby making my button a little bigger.
Now I really need this screen space, and I usually create a text element (disabled) that creates a much smaller component size (less space around my text) and adds a list to it. saves space. but uncomfortable. Is there a better way to create a tiny button? (when I try to make it smaller, it quickly puts "..." inward, although it does have room for much larger text)

10x

+7
source share
3 answers

You just need to install the "Insert" ...

jButton1.setText("jButton1"); jButton1.setMargin(new java.awt.Insets(1, 2, 1, 2)); 

Integer arguments: int top, int left, int bottom, int right

+8
source

Have you tried to set the button size?

jButton. setMinimumSize (new Dimension(width, height))
jButton. setPreferredSize (new Dimension(width, height))
jButton. setMaximumSize (new Dimension(width, height))

You should be able to achieve the desired results using a combination of these methods, as well as indicate the edge of your button, which controls the space between the text and the edges, i.e.

jButton. setMargin (new Insets(top, left, bottom, right))

+2
source

If you use the NetBeans GUI-builind, this can be achieved under the "margin" property of the button, changing its value to the type "user code" and the value "new java.awt.Insets (1, 2, 1, 2)"

0
source

All Articles