Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Nimbus' TableCellRenderer for boolean doesn't paint the alternate row color

843807Feb 28 2010 — edited Mar 1 2010
Watch for yourself:
import javax.swing.*;
import javax.swing.table.*;
public class BooleanTable implements Runnable {
	public static void main(String[] args) throws Exception {
		for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
			if ("Nimbus".equals(info.getName())) {
				UIManager.setLookAndFeel(info.getClassName());
				break;
			}
		}
		SwingUtilities.invokeLater(new BooleanTable());
	}
	@Override
	public void run() {
		JTable table = new JTable(new Model());
		JFrame frame = new JFrame(getClass().getSimpleName());
		frame.add(new JScrollPane(table));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}
	static class Model extends AbstractTableModel {
		@Override
		public int getColumnCount() { return 2; }
		@Override
		public String getColumnName(int col) { return getColumnClass(col).getSimpleName(); }
		@Override
		public Class<?> getColumnClass(int col) { return col==0 ? Number.class : Boolean.class; }
		@Override
		public int getRowCount() { return 100; }
		@Override
		public Object getValueAt(int row, int col) { return col==0 ? row : row%3==0; }
	}
}
Feature or Bug?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2010
Added on Feb 28 2010
1 comment
106 views