• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic