Insets not respected

I'm writing a calendar panel to use in an application. To display days I use JButtons. Since I don't want the buttons to take a lot of space they have no insets.

Here is how it looks in my GTK+: All buttons are displayed nice and clean.

Now here is how things look when I switch to the Metal laf: Simply said, this isn't acceptable.

When I set the insets by putting setMargins(new insets(0,0,0,0)) in the constructor of the custom button all works and it looks like I want it to look.

Now those buttons aren't the only buttons affected in a negative way and I don't feel like I should set this everywhere manually so I need a cleaner solution. I've tried setting the default button margin through UIManager.put("Button.margin", new Insets(0, 0, 0, 0)); but this didn't affect anything. This is driving me nuts, and I don't know how this affects other lafs like Aqua or Windows laf but I fear the worst.

Edit: Just tested it in Windows XP and guess what:

Edit2: The Main() creates and shows this frame. It has several components on it who are created by initComponents(). The initComponents() was created by Netbeans and it has a pack() at the end.

public class MainForm
    extends javax.swing.JFrame
{
    public MainForm()
    {
        String os = System.getProperty("os.name").toLowerCase();
        String laf = null;
        if (os.contains("win"))
        {
            laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
        }
        else if (os.contains("nix") || os.contains("nux"))
        {
            laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
        }
        else if (os.contains("mac"))
        {
            laf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
        }
        try
        {
            UIManager.put("Button.margin", new Insets(0, 0, 0, 0));
            UIManager.setLookAndFeel(laf);
            SwingUtilities.updateComponentTreeUI(this);
            System.out.println(UIManager.getLookAndFeel().toString());
        }
        catch (Exception ex)
        {
            System.out.println(ex.toString());
        }
        initComponents();
    }
}

Answers


All right I solved my issue and of course it was actually quite simple, here it comes. The buttons I use in my calendar panel are JToggleButtons. The "Button.margin" only applies to JButtons. So all I needed to do was to add 1 line: UIManager.put("ToggleButton.margin", new Insets(0, 0, 0, 0));

A list of items you can set in the UIManager can be found here.


Need Your Help

Sql 2008 Restore backup file problem

sql sql-server

I have a sql database backup in my system with extension *.bak.

Loading Alternative UITabBarController for iPhone5 support

iphone ios uitabbarcontroller

I have to add support for iPhone5 to my app. Currently the appdelegate uses a nib that is a UITabBarController, and code like this. Works fine.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.