• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I add listeners to JTable cells?  RSS feed

 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can I add a listener to a cell in a table? I want to check the value in a cell and based upon the result I want to make another cell disabled or enabled.
Thanks
Pomchi
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please look into Table selection model. You need to use ListSelectionModel, addListSelectionListener, ListSelectionEvent,
You need also use: table.setCellSelectionEnabled(true);
Hope this help.
Ruilin
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ruilin,
I read about what you told me....but I guess using ListSelectionModel I can only access the currently active row no.(I read all the examples given in Java Sun tutorial)Can I add a listener to a particular cell not the entire row??
May be I am wrong so if you could give me some simple code or any such example that would be great.

Thanks again
Pomchi
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used it to select a single row when click in it.
table.setCellSelectionEnabled(true);
ListSelectionModel cellSelectionModel = table.getSelectionModel();
cellSelectionModel.setSelectionMode(ListSelectionModel.SINGL_SELECTION);
cellSelectionModel.addListSelectionListener(handler);
This selects a row.
I firmly believe you can also select a column. Then the intersection is the cess you select. Then you can do what you want.
You need to look the java-API for TableSelectionModel class.
hope this help.
Ruilin
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ruilin !!
I am going to read more about what you told me.
-Pomchi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!