| Author |
JTable row selection based on a character key pressed
|
Satish Rajanna
Greenhorn
Joined: Nov 17, 2009
Posts: 5
|
|
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
Joined: Jun 13, 2009
Posts: 1786
|
|
|
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
Joined: Nov 17, 2009
Posts: 5
|
|
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
Joined: Aug 18, 2009
Posts: 155
|
|
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
|
Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
|
 |
Satish Rajanna
Greenhorn
Joined: Nov 17, 2009
Posts: 5
|
|
Hi, I have done as you guys have said, problem solved.... thank you for your time..
|
 |
 |
|
|
subject: JTable row selection based on a character key pressed
|
|
|