简体   繁体   English

其他单元格值更改时,禁用JTable单元格可编辑

[英]Disable JTable cell editable when other cell value changes

Let's say I have a JTable with two columns, A and B. Let's say I also have a List/Vector/Array (any collection) that contains some Strings. 假设我有一个包含两列A和B的JTable。假设我还有一个包含一些字符串的List / Vector / Array(任何集合)。 When I am done editing cell at row x, column A (pressing enter or selecting another cell or component), I want the JTable to check if what I typed in column A at row x is in my List. 当我完成了X行A列的单元格编辑(按Enter键或选择另一个单元格或组件)后,我希望JTable检查我在X行A列中键入的内容是否在列表中。 If it is the case, I want to disable editing in Column B at row X and set that cell to "Ok". 如果是这种情况,我想在X行的B列中禁用编辑,并将该单元格设置为“确定”。

I have no idea how to do this. 我不知道该怎么做。 I have searched but found some cases that were different from mine. 我进行了搜索,但发现有些情况与我的不同。

Any help will be greatly apreciated. 任何帮助将不胜感激。

Cheers :) 干杯:)

What you need is a custom table model. 您需要的是自定义表模型。 The TableModel interface contains a method isCellEditable with wich you can controll this behaviour. TableModel接口包含一个isCellEditable方法,您可以控制此行为。 To render a cell with "OK" and maybe a colored background you have to use a custom CellRenderer 要使用“确定”以及可能是彩色背景渲染单元格,您必须使用自定义CellRenderer

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

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