• 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

Tabbing between editable cells in JTable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to be able to tab between cells and the cell to immediately go into edit mode Additionally I'd like it to
skip uneditable cells, so tabbing on a far right cell doesn't move to the label on the next row, but to the next editable cell in the next row.

This is from the posting:
https://coderanch.com/t/344392/GUI/java/Tabbing-between-cells-JTable

The solution works well, except it does not tab to the next editable column in the next row. It keeps going back to the first editable column in the same row.

Any suggestions?
Thanks
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I beleive the best way to handle this problem is define two addKeyListener. One for click and another for tab.

Catch the tab event as "addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e)
{
if(e.getKeyCode() == KeyEvent.VK_TAB)
{//add bussiness logic
}}}
Because for your problem the logic for tab event and lick event must be differnt.

And your bussinees logic for tab event may be like

if(e.getKeyCode() == KeyEvent.VK_TAB)
{
row = jTable1.getSelectedRow();
col = jTable1.getSelectedColumn();
if(col == 3){
row ++;
col = 0;
}
while(jTable1.isCellEditable(row, col) == false){

if(col == 3){
row ++;
col = 0;
}
col++;
}
jTable1.editCellAt(row, col);
jTable1.requestFocusInWindow();

}
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The solution works well, except it does not tab to the next editable column in the next row. It keeps going back to the first editable column in the same row.
Try running this as–is:
 
lakshmi yellanki
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the responses, got it to work.

Lakshmi
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic