JAVA,怎么获取JTable上加的JRadioButton状态??

就是右边的上和下,我想获取各选了哪个学期的课程。。String[]Term={"上","下"};table.getColumn("学期").setCellRenderer... 就是右边的上和下,我想获取各选了哪个学期的课程。。

String[] Term={"上","下"};
table.getColumn("学期").setCellRenderer(new RadioButtonRenderer(Term));
table.getColumn("学期").setCellEditor(new RadioButtonEditor(new JCheckBox(), new RadioButtonPanel(Term)));

public class RadioButtonEditor extends DefaultCellEditor {
RadioButtonPanel panel;
JRadioButton[] buttons;

public RadioButtonEditor(JCheckBox checkBox, RadioButtonPanel panel) {
super(checkBox);
this.panel = panel;
ButtonGroup buttonGroup = new ButtonGroup();
buttons = panel.getButtons();
for (int i = 0; i < buttons.length; i++) {
buttonGroup.add(buttons[i]);
}
}

public Component getTableCellEditorComponent(JTable table,
Object value, boolean isSelected, int row, int column) {
if (value instanceof Integer) {
panel.setSelectedIndex(((Integer) value).intValue());
}

return panel;
}

public Object getCellEditorValue() {
return new Integer(panel.getSelectedIndex());
}
}
表格下方有个“提交”按钮,我想在最后选好后按提交的时候 先获取课程的学期
展开
 我来答
LHXYZD
2015-05-18 · TA获得超过2204个赞
知道小有建树答主
回答量:900
采纳率:50%
帮助的人:673万
展开全部
额。。jtable里面放cellrenderer没用过。。
你可以试一下直接访问renderer render的那个object,就是那个panel还是什么的
追答
查了一下,你在表里面放的应该是boolean然后再用renderer显示那个boolean
A JTable isn't supposed to contain components. It's supposed to contain data (Strings, Integers, Booleans, Dates, etc.). The renderer's goal is to use a component (the same instance for multiple cells) to transform this data into a visual thing (a label, a radio button, an icon, ...). The editor's goal is to be able to display the data in an editable component, to accept a new value, and to change the value of the data with the data entered by the end user.

Don't store components in a JTable. Configure renderers and/or editors to render/edit the data if the default doesn't suit your needs.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式