简体   繁体   English

将JComboBox添加到每行具有特定数据的jTable

[英]adding JComboBox to a jTable with specific data per row

I am trying to add a JComboBox to the last column of my JTable . 我正在尝试将JComboBoxJTable的最后一列。 The JComboBox isn't for editing purposes but for traversing the JTable itself. JComboBox不是用于编辑目的,而是用于遍历JTable本身。 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 . 每行可以有多个需要进入JComboBox元素,当从框中选择一个值时,我需要滚动到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. 我所做的所有研究都特别指向了编辑器和渲染器,其中包括JComboBox中的数据按列设置,以便用户可以为行中的单元格选择值。 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/ simple example here , your job is only to move (hold) TableCellEditor to the last row in the TableView , 1 / 这里的简单示例,您的工作只是将TableCellEditor移动(保持)到TableView的最后一行,

2/ if JComboBox's Item changed then search in TableModel for TableRow (if every TableColumns ends with JComboBox ) 2 /如果JComboBox's Item发生了变化,那么在TableModel搜索TableRow (如果每个TableColumnsJComboBox结尾)

3/ then call myTable.changeSelection(row, column, false, false); 3 /然后调用myTable.changeSelection(row, column, false, false);

4/ possible fauls implemented and used RowSorter , RowFilter , then you have to get int row from TableView and convert that to the TableModel by using 4 /可能的fauls实现并使用RowSorterRowFilter ,然后你必须从TableView获取int行并通过使用将其转换为TableModel

int modelRow = convertRowIndexToModel(row);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM