简体   繁体   English

自定义TableCellEditor构造函数仅被调用一次吗?

[英]Is a custom TableCellEditor constructor only called once?

I have a JTable. 我有一个JTable。 One column in the JTable is assigned an extended TableCellEditor that displays an extended JComboBox. 在JTable中的一列分配了一个扩展的TableCellEditor,它显示了一个扩展的JComboBox。

There is a fixed list of 100 String objects that populates the comboboxes. 有一个固定的100个String对象列表,用于填充组合框。

The challenge: 挑战:

  • Design the JComboBoxes so that any selection is unique relative to other boxes? 设计JComboBoxes,使任何选择相对于其他Box而言都是唯一的吗? That is, if "A" is slected from the combobox in the first row, it is automatically removed from the list of each other combobox. 也就是说,如果从第一行的组合框中选择了“ A”,则会自动将其从其他组合框的列表中删除。
  • When a new room is added to the table, the combobox it contains should auto-populate to the first available list item. 当新房间添加到表中时,它包含的组合框应自动填充到第一个可用的列表项。

The problem: My comboboxes work beautifully. 问题:我的组合框工作得很好。 I can select items at will. 我可以随意选择项目。 I even have made some progress in eliminating already used items from the lists. 我什至在从列表中删除已经使用的项目方面也取得了一些进展。 But I can't figure out how to correctly auto-populate. 但是我不知道如何正确地自动填充。

I am very confused because it appears that my combobox constructor is only called once when the table is created, not once for each row. 我很困惑,因为看来我的组合框构造函数在创建表时只被调用一次,而不是每行一次。

Is this the case? 是这样吗 Is the constructor for a TableCellEditor only called once ever? TableCellEditor的构造函数是否仅被调用过一次? If so, how do I modify the behavior of each combobox as it come into existence? 如果是这样,我如何修改每个组合框的行为?

Thanks for your help! 谢谢你的帮助!

If you would like specific code, please let me know. 如果您需要特定的代码,请告诉我。 I don't know if you want me to paste in the whole classes. 我不知道您是否要我粘贴到整个课程中。

When a new room is added to the table, the combobox it contains should auto-populate to the first available list item. 当新房间添加到表中时,它包含的组合框应自动填充到第一个可用的列表项。

When you add a new row of data to the TableModel you must add the values of all columns in the row. 将新的数据行添加到TableModel时,必须添加该行中所有列的值。 This should not be a function of the editor. 这不应该是编辑器的功能。 The editor allows you to change values in the cell. 编辑器允许您更改单元格中的值。

我可以通过为组合框创建一个抽象超类来解决问题,该超类可以在建立数据时通过tablemodel扩展进行访问。

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

相关问题 为什么当我遍历每行的TableCellEditor列时,仅调用一次itemStateChanged? - Why is itemStateChanged only called once when I iterate through a columns TableCellEditor in each row? 自定义TableCellEditor仅适用于1列差异,并且已应用于所有 - Custom TableCellEditor only working on 1 Column Dispite applied to all JComboBox作为自定义TableCellEditor - JComboBox as a Custom TableCellEditor 为什么每个实例只能调用一次构造函数? - Why can a constructor be called only once per instance? 如何强制构造函数只调用一次没有单例模式? - How to force constructor is only called once without singleton pattern? 即使页面刷新,Java构造函数中的代码也仅被调用一次 - code in constructor in java is called only once even page refreshed 为什么枚举构造函数在 REST class 中只调用一次? - Why Enum constructor is called only once in REST class? Android自定义视图只会调用onDraw一次 - Android custom view only gets onDraw called once AADAuthenticationFilter 只调用一次 - AADAuthenticationFilter called only Once 当构造函数仅被调用一次时,volatile字段对于每个线程如何唯一? - How can a volatile field be unique to each thread when the constructor is only called once?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM