1 19 20 package org.netbeans.modules.tasklist.usertasks.treetable; 21 22 import java.awt.Component ; 23 import java.awt.Rectangle ; 24 25 import javax.swing.JCheckBox ; 26 import javax.swing.JLabel ; 27 import javax.swing.JTable ; 28 import javax.swing.UIManager ; 29 import javax.swing.border.Border ; 30 import javax.swing.border.EmptyBorder ; 31 import javax.swing.table.DefaultTableCellRenderer ; 32 import javax.swing.table.TableCellRenderer ; 33 34 37 public class BooleanTableCellRenderer extends JCheckBox 38 implements TableCellRenderer { 39 private DefaultTableCellRenderer def = new DefaultTableCellRenderer (); 40 protected static Border noFocusBorder = new EmptyBorder (1, 1, 1, 1); 41 42 45 public BooleanTableCellRenderer() { 46 setHorizontalAlignment(JLabel.CENTER); 47 setBorder(noFocusBorder); 48 setBorderPainted(true); 49 setBorderPaintedFlat(true); 50 setOpaque(true); 51 } 52 53 public Component getTableCellRendererComponent(JTable table, Object value, 54 boolean isSelected, boolean hasFocus, int row, int column) { 55 if (value == null) 56 return def.getTableCellRendererComponent(table, value, 57 isSelected, hasFocus, row, column); 58 if (isSelected) { 59 setForeground(table.getSelectionForeground()); 60 super.setBackground(table.getSelectionBackground()); 61 } 62 else { 63 setForeground(table.getForeground()); 64 setBackground(table.getBackground()); 65 } 66 67 if (hasFocus) { 68 setBorder(UIManager.getBorder("Table.focusCellHighlightBorder") ); } else { 70 setBorder(noFocusBorder); 71 } 72 73 setSelected((value != null && ((Boolean )value).booleanValue())); 74 return this; 75 } 76 } 77 | Popular Tags |