I've created a JTable
whose columns contain a variety of different components. The last five columns either contain nothing (a DefaultTableCellRenderer
with no value) or a JRadioButton
using a custom renderer and editor. The renderer creates and returns a new radioButton in the cells I need one, and I want to access these radio buttons from my panel class to add them to a ButtonGroup
. I am using the following piece of code that I wrote:
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()
keeps returning null regardless of what is contained in the cell, whether it be a JCheckBox
, JRadioButton
, JComboBox
... everything is returned as null.
Is there an alternative way to get the cell's component? Or is there a way for me to get this to work? Thank you!