如何将JRadioButton添加到JTable中的组中
JTable
class RadioButtonRenderer implements TableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (value == null) return null; return (Component) value; }}class RadioButtonEditor extends DefaultCellEditor implements ItemListener { private JRadioButton button; public RadioButtonEditor(JCheckBox checkBox) { super(checkBox); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (value == null) return null; button = (JRadioButton) value; button.addItemListener(this); return (Component) value; } public Object getCellEditorValue() { button.removeItemListener(this); return button; } public void itemStateChanged(ItemEvent e) { super.fireEditingStopped(); }}
private void displayPhoneListShow(Person person) { DefaultTableModel dm = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { return true; } }; Object[] objects = new Object[3]; Object[] tableColumnNamesPhone = new Object[3]; tableColumnNamesPhone[0] = "Select"; tableColumnNamesPhone[1] = "Phone Number"; tableColumnNamesPhone[2] = "Preferred";
ButtonGroup group = new ButtonGroup()
RadioButtonRenderer
一只名叫tom的猫
相关分类