我正在尝试将 JComboBox
添加到我的 JTable
的最后一列。 JComboBox
不是用于编辑目的,而是用于遍历 JTable
本身。每行可以有 0 个需要放入 JComboBox 中的元素,当从框中选择一个值时,我需要滚动到 JTable 中的不同行。
我所做的所有研究都专门针对编辑器和渲染器,其缺点是 JComboBox 中的数据是每列设置的,以便用户可以为行中的单元格选择一个值。我需要特定于该行的值。
所以我的问题是,以前有人尝试过这样做吗?你能给我提供一些关于如何做到这一点的好信息吗?或者您能描述一下您是如何做到这一点的吗?
I am trying to add a JComboBox
to the last column of my JTable
. The JComboBox
isn't for editing purposes but for traversing the JTable
itself. Each row can have 0-many elements that need to go in the JComboBox
and when a value is selected from the box I need to scroll to a different row in the JTable
.
All the research I have done points me specifically to editors and renderers with the down fall being that data in the JComboBox
is set per column so that a user can select a value for the cell in the row. Where as I need values that are specific to the row.
So my question is, has anyone tried to do this before? and Can you point me to some good information on how to do this? or even better could you describe how you did this?
发布评论
评论(1)
1/简单示例 这里,您的工作只是将
TableCellEditor
移动(按住)到最后一行TableView
,2/ 如果
JComboBox 的 Item
更改,则在TableModel
中搜索TableRow
(如果每个TableColumns< /code> 以
JComboBox
结尾)3/ 然后调用
myTable.changeSelection(row, column, false, false);
4/ 实现和使用的可能错误
RowSorter
、RowFilter
,然后您必须从TableView
获取 int row 并将其转换为TableModel
使用1/ simple example here, your job is only to move (hold)
TableCellEditor
to the last row in theTableView
,2/ if
JComboBox's Item
changed then search inTableModel
forTableRow
(if everyTableColumns
ends withJComboBox
)3/ then call
myTable.changeSelection(row, column, false, false);
4/ possible fauls implemented and used
RowSorter
,RowFilter
, then you have to get int row fromTableView
and convert that to theTableModel
by using