0

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. 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. If it is the case, I want to disable editing in Column B at row X and set that cell to "Ok".

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 :)

kleopatra
  • 51,061
  • 28
  • 99
  • 211
user2154283
  • 291
  • 1
  • 5
  • 14

1 Answers1

1

What you need is a custom table model. The TableModel interface contains a method isCellEditable with wich you can controll this behaviour. To render a cell with "OK" and maybe a colored background you have to use a custom CellRenderer

Community
  • 1
  • 1
My-Name-Is
  • 4,814
  • 10
  • 44
  • 84
  • Hey :) thanks for the reply ! I got it to work, but the problem now is that when i edit column A, I need to click on column B to be able to see it say "OK" and change background color. i would want that to happen when I'm done editing column A. – user2154283 Jun 08 '13 at 20:25
  • (i.e without having to click on column B cell to see the changes. I know that the problem comes from the fact that isCellEditable is only invoked when I click on column B, and that's why I'd want to be abl to invoke it myself so it updates the UI) (I've tried updateUI() but it doesn't do anything). – user2154283 Jun 08 '13 at 20:27
  • Nevermind, found it ! I used fireTableDataChanged() in a TableModelListener and now it works :) Thanks again for the help ! – user2154283 Jun 08 '13 at 21:12