单选按钮和 setSelected 还是别的什么? [英] Radio buttons and setSelected or something else?

查看:45
本文介绍了单选按钮和 setSelected 还是别的什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JFrame 表单,其中包含标签、文本字段、一个组合框和一个包含 2 个单选按钮的按钮组.在另一个表单中,我有一个 JTable 填充了有关学生的数据(学生 ID、姓名...),当我从表中选择一行时,表单打开并且它的字段需要填充相同的值(例如,如果 PeterPeterson 是从表中选择的,那么他的名字应该显示在表单上的文本字段 Name 中,所以我做了 txtfieldName.setText(student.getName),我的问题是如何为单选按钮执行此操作?我需要有表中是/否列,所以当我选择一个表行,其中的值是是"以便在表单上选择是单选按钮?

I have a JFrame form with labels, text fields, a combo box and a button group that has 2 radio buttons. In another form I have a JTable filled with data about students (student id, name...), and when I select a row from a table, the form opens and its field need to be filled with same values (eg. if Peter Peterson was selected from the table, then his name should be shown in text filed Name on the form, so I did txtfieldName.setText(student.getName), my question is how do I do this for radio button? Do I need to have yes/no column in the table, so when I select a table row where the value is, say, ''yes'' in order to have yes radio button selected on the form?

推荐答案

if (result.getString(5).equals("Male")) {
     jRadioButton1.setSelected(true);
} else { 
     jRadioButton2.setSelected(true);
}

这篇关于单选按钮和 setSelected 还是别的什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆