1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| public class MyTable extends JTable {
/** Creates a new instance of MyTable */
public MyTable() {
super();
setDefaultRenderer(Object.class, new MyCellRenderer());
//setDefaultEditor(Object.class, new MyCellEditor());
}
}
class MyCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object obj, boolean sel, boolean foc, int row, int col) {
JLabel lbl = null;
JCheckBox chk = null;
JComboBox cmb = null;
JButton btn = null;
JRadioButton rdb = null;
switch (row) {
case 0:
lbl = new JLabel();
return lbl;
break;
case 1:
chk = new JCheckBox();
return chk;
break;
case 2:
cmb = new JComboBox();
return cmb;
break;
case 3:
btn = new JButton();
return btn;
break;
case 4:
rdb = new JRadioButton();
return rdb;
break;
default :
lbl = new JLabel();
return lbl;
}
}
} |
Partager