Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a button exactly the same size of its text?

Is it possible to make a JButton take exactly the size of its text? Since by default, a JButton will have a small amount of padding (both horizontal and vertical) around its text. I would like to remove that padding.

like image 402
PB_MLT Avatar asked Apr 26 '10 10:04

PB_MLT


People also ask

How do I make all Divi buttons the same size?

Making Divi Buttons the Same Size Normally the Call-to-Action (CTA) buttons in the Divi Theme adjust in size to fit the text they contain. If you'd prefer to have a standard button width throughout your site, here's how to do it. Setting the Minimum Button Width using CSS

Is there a way to force buttons to be the same size?

Is there a way of forcing the buttons to all be the same size, regardless of the text label? yep. Basically, if you want them the same size, you have to give the same width. First, in your html put the items in a list, and put the list inside a division (for this example I’ll call the div “navigation”)

How do I set the width of a button?

To have a standard button width throughout your site, you can use the following CSS:.et_pb_button { min-width: 180px; text-align :center; } Should you wish to apply it only to certain Divi Builder modules, you can give the module a CSS class (in the module settings). Then you can set the CSS as follows:

How do I change the size of a button in CSS?

Just replace your-css-class with the CSS class you specify in the module settings. This tip actually works by setting a minimum size on the buttons, so that if you do have any buttons longer than the standard width, they'll still display correctly.


2 Answers

Clear out the margins in the button with setMargin.

Removing the border has the side-effect of removing the border. If you only want to clear out the margins, use the setMargin method to set the margins all to zero.

button.setMargin(new Insets(0,0,0,0));
like image 140
Eugene Ryzhikov Avatar answered Oct 23 '22 05:10

Eugene Ryzhikov


JButton has a border by default, you can remove it:

button.setBorder(null);

If you want to keep the border, reduce the margin (see Eugenes answer)

like image 43
Peter Lang Avatar answered Oct 23 '22 06:10

Peter Lang