• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tabbing between editable cells in JTable

 
lakshmi yellanki
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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:
http://www.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
 
Ramakanta Biswal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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();

}
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the responses, got it to work.

Lakshmi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic