英文:
Get all checked value from the table
问题
这是我需要的输出:
这是我目前编写的代码:
TableModel model = table_test.getModel();
for (int i = 0; i < model.getRowCount(); ++i) {
Boolean isChecked = Boolean.valueOf(model.getValueAt(i, 0).toString());
String col = model.getValueAt(i, 1).toString();
if (isChecked == true) {
try {
textarea.setText(col);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
这段代码只会在文本区域显示一个值。
希望你能帮我解决这个问题。
英文:
I'm trying to get all value from a table where the checkbox is checked, I've make codes but it only gets one output and not working if I checked randomly you have to start checking from the start to make it work.
This the Output I need:
this my current codes I've make:
TableModel model = table_test.getModel();
for(int i=0; i<model.getRowCount();++i)
{
Boolean isChecked = Boolean.valueOf(model.getValueAt(i, 0).toString());
String col = model.getValueAt(i,1).toString();
if (isChecked==true) {
try{
textarea.setText(col);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
this codes only display is one value at the text area.
I hope you can help me with this problem.
答案1
得分: -1
你可以尝试以下代码:
TableModel model = table_test.getModel();
for (int i = 0; i < model.getRowCount(); ++i) {
Boolean isChecked = Boolean.valueOf(model.getValueAt(i, 0).toString());
String col = model.getValueAt(i, 1).toString();
if (isChecked == true) {
try {
textarea.append(col);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
英文:
You can try below.
TableModel model = table_test.getModel();
for(int i=0; i<model.getRowCount();++i)
{
Boolean isChecked = Boolean.valueOf(model.getValueAt(i, 0).toString());
String col = model.getValueAt(i,1).toString();
if (isChecked==true) {
try{
textarea.append(col);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论