简体   繁体   English

无法编辑表格单元格:Java Swing

[英]Cannot edit table cell: Java Swing

I created a custom table using BeanTableModel as tableModel (not sure if this matters). 我使用BeanTableModel作为tableModel创建了一个自定义表(不确定是否重要)。 The table populates data from an enum Object, and shoudl write to the object as well. 该表将填充枚举对象中的数据,并且也应向该对象中写入。 Currently the behavior is that the table will populate the data correctly. 当前的行为是该表将正确填充数据。 If i write in a cell, I can. 如果我在单元格中写,我可以。 But when i tab, the cell is outlined in RED and i can only ESC, which returns the cell to normal with original data. 但是,当我使用Tab键时,该单元格以红色标注轮廓,而我只能进行ESC,这会使单元格恢复原始数据的正常状态。 I want to be able edit the table and save the data. 我希望能够编辑表并保存数据。

What are some possible fixes or points of problem? 有哪些可能的解决方法或要点?

CellEditor accepting inputed value that corresponding with Class.types , for example CellEditor接受与Class.types相对应的输入值

  • in the case that Column Class is Number , then CellEditor accepting only Numbers , decimal separator and negative sign , 如果Column Class is Number ,则CellEditor仅接受Numbersdecimal separatornegative sign

  • most complicated could be input correct value for plain Date Class 最复杂的可能是为普通Date类输入正确的值

  • depends of Class.types and Formatters that are sets in your BeanTableModel 依赖的Class.typesFormatters是套在你的BeanTableModel

  • for better help sooner post an SSCCE 为了更好的帮助,尽快发布SSCCE

the cell is outlined in red . 单元格用红色勾勒出轮廓。

As illustrated here , this is the behavior of the default editor , JTable.GenericEditor . 如图所示这里 ,这是行为默认编辑器JTable.GenericEditor This suggests that your TableModel has an incorrect implementation of getColumnClass() , as others have suggested. 这表明您的TableModel有一个不正确的getColumnClass() ,正如其他人建议的那样。 Please edit your question to include an sscce , which may help isolate the problem. 请编辑您的问题以包含sscce ,这可能有助于找出问题所在。

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

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