DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); table.setDefaultRenderer(Object.class, renderer);
JCheckBox checkBox = new JCheckBox(); checkBox.setHorizontalAlignment(SwingConstants.CENTER); table.setDefaultRenderer(Boolean.class, new DefaultTableCellRenderer() { protected void setValue(Object value) { super.setValue(null); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { boolean b = value != null && ((Boolean) value).booleanValue(); checkBox.setSelected(b); return checkBox; } });This example sets a default renderer for all Boolean values in a table that displays a checkbox instead of the actual value. The code examples shown use the javax.swing package library.