• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable row selection based on a character key pressed

 
Satish Rajanna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am developing a File Explorer. I am displaying the contents of a directory in a JTable (all files and sub directories). The first column contains the icon of the file type (file or directory) , second column filename, third file size and fourth creation date. When I click on any file (row) and press an alphabetical key i should be able to select the file (row) with filename starting with that key pressed. i.e if I press 't' , i should be able to select a file say "test.doc". How do I do this ? any help greatly appreciated.
 
Rob Camick
Ranch Hand
Posts: 2615
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add KeyListener to the table. Then loop through the TableModel using the getVaueAt(...) method to see if the data starts with the character you typed.
 
Satish Rajanna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:Add KeyListener to the table. Then loop through the TableModel using the getVaueAt(...) method to see if the data starts with the character you typed.


Thanks Rob for the suggestion. But I was looking for some other easier way to do it.. anyway will give a try for this..
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi satish. that is the only way
if you do not add a key listener to the JTable, then the JTable will not have any capability to listen for keys pressed
 
Satish Rajanna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have done as you guys have said, problem solved.... thank you for your time..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic