• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Disabling JTable Cell selections

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JTable that contains several columns of data that I want
to not be selectable. What I am wanting to achieve is that when the user uses the tab key to move around the table for these cells/columns to be skipped. That way only the cells that can be edited are tabbed to whenever the tab key is used for navigation.
Does anyone have any ideas here on how I can do this?
Lon Allen
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I came across the same problem and struggled with it for a couple of days, but finally got it figured out.
You need to implement isCellEditable(row,col) in your data model to return the appropriate boolean flag for the cells. Then add a key listener to the table and implement the keyReleased method to check for VK_TAB key code, if it is the tab key, then loop through your table, checking to see if the cell is editable. If editable, call changeSelection method to change to the next editable cell.
The logic is actually a bit more involved than this, but this should get you started. The other thing I would do is add a focus listener to clear selection on focus lost and change selection to the first editable cell on focus gained. Also, if you are planning to tab out of the table using the tab key as opposed to CTRL TAB, then you need to use the focus manager when you are tabbing out of the last editable cell.
Good luck!
Sayuri
 
Lon Allen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the ideas. I had thought that I might need to do something along these lines, but was hoping that somehow it might be easier.
Lon Allen
 
Sayuri Coppinger
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I thought the same thing but no such luck. BTW, if your table is contained in a scrollpane, you might run into some problems traversing the table with the tab key. You will need to tab twice and sometimes even 3 times! This is a known bug. I actually ended up taking my table out of the scrollpane to get the behaviour I wanted.
Just some things to keep in mind....Like I said I did struggle to get it working
 
Lon Allen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks...
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am also in need of disabling the JTable cells, and to traverse thro' only the editable cells of Jtable. I found the discussions in this thread could give me a solution.
But i am struggling where to start, and i couldn't find the method changeSelection() in javadoc api.
Could u help me... with some samples
Thanks in advance,
-Sakthi
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
changeSelection() is under JTable in the API.
reply
    Bookmark Topic Watch Topic
  • New Topic