aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Tabbing between editable cells in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Tabbing between editable cells in JTable" Watch "Tabbing between editable cells in JTable" New topic
Author

Tabbing between editable cells in JTable

lakshmi yellanki
Greenhorn

Joined: Aug 22, 2008
Posts: 2
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

Joined: Aug 21, 2008
Posts: 9
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

Joined: Jan 14, 2004
Posts: 1535
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

Joined: Aug 22, 2008
Posts: 2
Thanks for the responses, got it to work.

Lakshmi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tabbing between editable cells in JTable