Nimbus JTable Checkbox Rendering Bug
I ran across a Nimbus Look and Feel bug that affects the GUIs I work on. This is a known issue: see Bug ID 6723524 on the Bug Parade. It is marked Low priority, so I hope it is fixed before the Java 6u10 release. (unlike Bug 4795987, for example, which has been open since 2002 and is also affecting my GUIs).
Here is a standard JTable with Boolean values in the third column. Notice how the standard checkbox renderer fails to properly paint alternate row colors: (this is very subtle on some displays)

In this next picture, I clicked on “Jones” to demonstrate the standard Nimbus focus border:

In this next picture, I clicked on the checkbox. Notice how the border is not painted on the checkbox renderer:

Sample Code
Here is the demonstration program, it requires JDK 1.6u10 to run.
import javax.swing.*;
import static javax.swing.UIManager.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
/**
* Demonstrates bug 6723524, checkboxes do not render properly in JTable.
*
* @author Eric M. Burke
*/
public class NimbusDemo extends JFrame {
public static void main(String... args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
setNimbusLaf();
new NimbusDemo().setVisible(true);
}
});
}
private static void setNimbusLaf() {
try {
for (LookAndFeelInfo lafInfo : getInstalledLookAndFeels()) {
if ("Nimbus".equals(lafInfo.getName())) {
setLookAndFeel(lafInfo.getClassName());
return;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
throw new RuntimeException("Unable to find Nimbus LAF.");
}
public NimbusDemo() {
super("Bug 6723524");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object[] columnNames = {
"First Name", "Last Name", "Married"
};
Object[][] data = {
{"Harry", "Smith", true},
{"Sally", "Jones", false},
{"Bob", "Clark", true},
{"Eric", "Burke", true}
};
TableModel tm = new DefaultTableModel(data, columnNames) {
public Class getColumnClass(int columnIndex) {
return (columnIndex == 2) ? Boolean.class : String.class;
}
public boolean isCellEditable(int row, int column) {
return false;
}
};
add(new JScrollPane(new JTable(tm)), BorderLayout.CENTER);
pack();
}
}
Not yet in Java 6u11…
Not yet to resolve in java 6.13
I posted a work-around at the Bug Parade. It works rather well for me. Give it a try.
Dirk