JTable -gt; TableModeListener(JTable -表模式监听器)
问题描述
我有这个 JTable
有一个 DefaultTableModel
作为它的模型.在桌子上,我有几个摆动组件,JComboBox
和 JCheckBox
,通过 DefaultCellEditor
和 DefaultCellRenderer
在特定列上设置.TableModelListener
已添加到表中以捕获可编辑列的更改.其余列将显示所选组件的详细信息,即商品代码 -> 商品价格、商品数量、商品分类等.
I have this JTable
having a DefaultTableModel
as its model.
On the table I have several swing component, JComboBox
and JCheckBox
, set on a particular column via DefaultCellEditor
and DefaultCellRenderer
.
The TableModelListener
was added to the table to capture changes on editable columns.
The rest of the columns will display details of the selected component, i.e. item code -> item price, item count, item classification,etc.
我有这个问题,如果 JComboBox(itemCode)
的 selectedItem 发生变化,其他 JComboBox(itemClassification)
的项目也会发生变化.但随着其他 JComboBox 的变化,我需要在同一张桌子上显示商品价格.此更改重新触发 valueChanged
方法,该方法使 valueChanged
无限循环.
I have this problem wherein if the selectedItem of the JComboBox(itemCode)
changes, the items of the other JComboBox(itemClassification)
changes. But together with the change of the other JComboBox I need to display the item price on the same table. This change refires the valueChanged
method which makes an infinite loop of valueChanged
.
我怎样才能摆脱无限循环的东西?
How can I get rid of the infinite loop thing?
推荐答案
一种方法是检查更新事件以查看该事件是针对哪一列并忽略自动更新的列:
One way is to check the update event to see what column the event is for and ignore columns that are automatically updated:
这篇关于JTable ->表模式监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!