Search code examples
javalinuxswingjtablenimbus

Linux - Nimbus LookAndFeel : Table Grid Lines are not coming


In my java application I am using NimBusLookAndFeel. I was trying to show grid lines in table.

Following code works perfectly fine on windows but not on Linux (table grid lines do not appear in linux)

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
UIManager.put("Table.showGrid", true);
UIManager.put("Table.intercellSpacing", new Dimension (1,1)); 

Following are java version details on linux

java version "1.6.0_12" Java(TM) SE Runtime Environment (build 1.6.0_12-b04) Java HotSpot(TM) Server VM (build 11.2-b01, mixed mode)


Solution

  • you have to overrive following Nimbus UIDefaults

    try {// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if (info.getName().equals("Nimbus")) {
                UIManager.setLookAndFeel(info.getClassName());
                UIDefaults defaults = UIManager.getLookAndFeelDefaults();
                defaults.put("Table.gridColor", new Color (214,217,223));
                defaults.put("Table.disabled", false);
                defaults.put("Table.showGrid", true);
                defaults.put("Table.intercellSpacing", new Dimension(1, 1));
                break;
            }
        }
    } catch (Exception e) {
        //e.printStackTrace();
    }