javaswingjbuttonnimbusuidefaults

JButton margins. Not respected when nimbus plaf


The property margin of a JButton isn't respected when the nimbus look and feel is installed.
. I need some "little" buttons, but nimbus forces the space around button text to be large, so I only get "very large" buttons.
I discovered in nimbus defaults page that there is a property called:

Button.contentMargins

that is preset with large values.
I've tryed to override it with the following code:

UIManager.getDefaults().put("Button.contentMargins", new InsetsUIResource(0,0,0,0));

in the main, just after setting the nimbus look and feel.

But nothing happens, the empty space around buttons text still remains large. Any idea?


Solution

  • Altering the value of the JComponent.sizeVariant may also be effective, as discussed in Resizing a Component.