0

JTable列にさまざまなコンポーネントが含まれている を作成しました。最後の 5 列には、何も含まれていない (DefaultTableCellRenderer値がない) かJRadioButton、カスタム レンダラーとエディターを使用しています。レンダラーは、必要なセルに新しい radioButton を作成して返します。パネル クラスからこれらのラジオ ボタンにアクセスして、ButtonGroup. 私が書いた次のコードを使用しています。

protected void setButtonGroups() {
    buttonGroups = new ArrayList<ButtonGroup>();
    for (int i = 0; i < tableModel.getRowCount(); i++) {
        ButtonGroup currentGroup = new ButtonGroup();
        for (int j = 0; j < tableModel.getColumnCount(); j++) {
            if (table.getComponentAt(i, j) != null) {
                    currentGroup.add((JRadioButton)table.getComponentAt(i, j));
                }
            }
        }
        buttonGroups.add(currentGroup);
    }
}

getComponentAt()セルに何が含まれているかに関係なくJCheckBox、セルに含まれているものに関係なく、null を返し続けます。JRadioButtonJComboBox

セルのコンポーネントを取得する別の方法はありますか? または、これを機能させる方法はありますか?ありがとうございました!

4

1 に答える 1