views:

146

answers:

2

I have a small "popup" like this:

Tiny button

But I don't want the padding around the button, I want it to be as small as it can be with the supplied text.

btn.setMargin(new Insets(1, 1, 1, 1));
panel.add(lbl, "wrap");
panel.add(btn);
frame.pack();
frame.setVisible(true);

At least this doesn't work... Can this be achieved on MigLayout or should I use some other layout manager for this frame.

+1  A: 

A layout manager should not affect the way a component is painted.

The setMargin(...) works fine for me when using the Metal LAF. Maybe your LAF doesn't support the setMargin() method. Or maybe you have some code elsewhere that is overriding the preferred size of the button causing it to paint like this.

However, if the MIG layout turns out to be the problem, you could try the Wrap Layout.

camickr
Thanks a lot! It's the Substance Creme look and feel that's causing it.
Indrek
But it seems to me that all substance skins do this... Any way around it?
Indrek
+1  A: 

What's your MigLayout constraints that it was built with? You might want to try using novisualpadding if you aren't already. Also, the debug layout constraint will draw boxes around your components to show what room they take up. (I think the red dotted lines are the size of the components and the blue dotted lines are the "cells" that the component is in.)

// old version
// JPanel panel = new JPanel(new MigLayout());

// new verion
JPanel panel = new JPanel(new MigLayout("debug, novisualpadding"));

I use MigLayout pretty often and have found the "cheat sheet" pretty useful. http://migcalendar.com/miglayout/cheatsheet.html

Mike