I have jtable i want select multiple row and get that values into the Array.how i suppose to do that
我有jtable我想选择多行并将值传入Array.how我想这样做
My jTable
2 个解决方案
#1
1
i want select multiple row
我想选择多行
This is supported by default in a JTable. You just hold the "Ctrl" key when you click on other rows.
JTable默认支持此功能。单击其他行时,只需按住“Ctrl”键即可。
get that values into the Array
将这些值放入Array中
What values?
If you just want the row that is selected you use the getSelectedRows()
method of the JTable
.
如果您只想要选择的行,则使用JTable的getSelectedRows()方法。
If you want the data of the selected rows then you use the above method and create a loop and use the getValueAt(...)
method to get the data from each cell.
如果你想要所选行的数据,那么你使用上面的方法并创建一个循环并使用getValueAt(...)方法从每个单元格中获取数据。
Edit:
when i select check box in first column i want to get EMP ID in that checked row
当我在第一列中选中复选框时,我想在该选中的行中获取EMP ID
So usually you have a "Process Selected Rows" button on the form. Then when you click the button you loop through the TableModel and use the getValueAt(...) method to check if the first column is selected. If it is selected then you do your processing.
所以通常你在表单上有一个“Process Selected Rows”按钮。然后,当您单击按钮时,循环遍历TableModel并使用getValueAt(...)方法检查是否选择了第一列。如果已选中,则进行处理。
#2
0
Its required to allow multiple selection by
它需要允许多个选择
table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Then you can write list selection Lister like this example
然后你可以像这个例子一样编写列表选择Lister
#1
1
i want select multiple row
我想选择多行
This is supported by default in a JTable. You just hold the "Ctrl" key when you click on other rows.
JTable默认支持此功能。单击其他行时,只需按住“Ctrl”键即可。
get that values into the Array
将这些值放入Array中
What values?
If you just want the row that is selected you use the getSelectedRows()
method of the JTable
.
如果您只想要选择的行,则使用JTable的getSelectedRows()方法。
If you want the data of the selected rows then you use the above method and create a loop and use the getValueAt(...)
method to get the data from each cell.
如果你想要所选行的数据,那么你使用上面的方法并创建一个循环并使用getValueAt(...)方法从每个单元格中获取数据。
Edit:
when i select check box in first column i want to get EMP ID in that checked row
当我在第一列中选中复选框时,我想在该选中的行中获取EMP ID
So usually you have a "Process Selected Rows" button on the form. Then when you click the button you loop through the TableModel and use the getValueAt(...) method to check if the first column is selected. If it is selected then you do your processing.
所以通常你在表单上有一个“Process Selected Rows”按钮。然后,当您单击按钮时,循环遍历TableModel并使用getValueAt(...)方法检查是否选择了第一列。如果已选中,则进行处理。
#2
0
Its required to allow multiple selection by
它需要允许多个选择
table.setRowSelectionAllowed(true);
table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Then you can write list selection Lister like this example
然后你可以像这个例子一样编写列表选择Lister