gpt4 book ai didi

java - 如何在运行时添加单选按钮

转载 作者:行者123 更新时间:2023-11-30 04:20:41 25 4
gpt4 key购买 nike

我正在使用 Netbeans 7.1 和 MySQL。我需要 jtable 中的 1 列,其中将包含 jradiobutton,并且用户可以选择任意 1 行的 jradiobutton详细请引用图。选择RB后,将对jbutton点击事件进行进一步处理。

enter image description here

这是代码-

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
final Object[] columnNames=new String[] {"Date","Flight Name","Departure Time","BC Seats Available","XC Seats Available","EC Seats Available"};
DefaultTableModel dtm=new DefaultTableModel(columnNames,0);
String origin=jComboBox3.getSelectedItem().toString();
String target=jComboBox4.getSelectedItem().toString();
String fclass=jComboBox1.getSelectedItem().toString();
String search = "";
Date dt;

//Economy Class Processing

try
{
smt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = smt.executeQuery(sql);
int i = 0;
SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy");
boolean empty=true;
String var1="", var2="", var3="", var4="", var5="";
while(rs.next())
{
empty=false;
var1=rs.getString(1);
strdtver1=(String) sdf.format(rs.getDate(2));
var2=Integer.toString(rs.getInt(3));
var3=Integer.toString(rs.getInt(4));
var4=Integer.toString(rs.getInt(5));
var5=rs.getString(6);
dtm.addRow(new Vector());
dtm.setValueAt(strdtver1, i, 0);
dtm.setValueAt(var1, i, 1);
dtm.setValueAt(var5, i, 2);
dtm.setValueAt(var2, i, 3);
dtm.setValueAt(var3, i, 4);
dtm.setValueAt(var4, i, 5);
i++;

}
if(empty)
{
dtm.addRow(new Vector());
strdtver2=(String) sdf.format(jDateChooser1.getDate());
dtm.setValueAt(strdtver2, i, 0);
dtm.setValueAt("No Flights", i, 1);
dtm.setValueAt("No Flights", i, 2);
dtm.setValueAt("0", i, 3);
dtm.setValueAt("0", i, 4);
dtm.setValueAt("0", i, 5);
}
jTable1.setModel(dtm);
TableColumnModel m=jTable1.getColumnModel();
TableColumn col=m.getColumn(3);
TableColumn col1=m.getColumn(4);
//List<TableColumn> removed=col;
//removed.add(col);
m.removeColumn(col);
m.removeColumn(col1);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}

我只是想添加 JRadioButton 并且用户可以选择任意 1 行 JRadioButto,

提前感谢大家的建议和指导

最佳答案

考虑了几种替代方案here ,但您可能想要因为@Guillaume Polet 显示的那个 here 。它使用 PropertyChangeEvent 来强制执行单行选择属性。

关于java - 如何在运行时添加单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17137550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com