Hi
When I create a button in swing it adds a border around my text, thus making my button a bit bigger.
Now, I really need that screen space and what I usually do is create a text item (disabled ) which create much smaller component size (smaller space around my text) and add to it a listner.
saves space. but awkward.
Is there a better way to create a tiny button? (when I try to make it smaller it quickly puts a "..." inside though it got room for much more text)
10x
Simply delete the frame. setPreferredSize() and the buttons will be small (the frame size will be determined by the preferred sizes of inner components by calling frame. pack() method).
The pack() method is defined in Window class in Java and it sizes the frame so that all its contents are at or above their preferred sizes. An alternative to the pack() method is to establish a frame size explicitly by calling the setSize() or setBounds() methods.
We can set a margin to a JButton by using the setMargin() method of JButton class and pass Insets(int top, int left, int bottom, int right) as an argument.
You just need to set The Insets narrower...
jButton1.setText("jButton1");
jButton1.setMargin(new java.awt.Insets(1, 2, 1, 2));
The integer arguments are: int top, int left, int bottom, int right
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With