小编mon*_*onk的帖子

如何在JTable中将JRadioButton添加到组中

我已经为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)

java swing jtable jradiobutton buttongroup

2
推荐指数
1
解决办法
8008
查看次数

标签 统计

buttongroup ×1

java ×1

jradiobutton ×1

jtable ×1

swing ×1