我已经为JTable使用渲染器和编辑器添加了单选按钮.我也创建了同样的组.我无法使用此原则实现排他性(只应选择1个单选按钮).请参阅下面的代码并感谢您的回复.
渲染器和编辑器类:
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 …Run Code Online (Sandbox Code Playgroud)