short cuts to jump between table columns

I have setup actions that would allow the user to use shortcut keys to jump between columns of a JTable. My code is as follows:

publicclass HotkeyActionListenerextends AbstractAction{

protected String m_cmd ="";

protected AppIFace m_appIFace =null;

public HotkeyActionListener(String actionCommand, AppIFace appIFace){

super(actionCommand);

m_cmd = actionCommand;

m_appIFace = appIFace;

}

publicvoid actionPerformed(ActionEvent event){

if (m_cmd.equals(HotkeyConstants.FOCUS_FIRST_COLUMN)){

m_appIFace.requestFocusOnFirstColumn();

}elseif (m_cmd.equals(HotkeyConstants.FOCUS_SECOND_COLUMN)){

m_appIFace.requestFocusOnSecondColumn();

}elseif{

....

}

}

publicclass MyTableFrameextends JFrame{

....

publicvoid setupTableShortCutKeys(){

setShortCutKey(HotkeyConstants.FOCUS_FIRST_COLUMN, m_appIFace);

setShortCutKey(HotkeyConstants.FOCUS_SECOND_COLUMN, m_appIFace);

...

}

publicvoid setShortCutKey(String type, AppIFace iFace){

HotkeyActionListener keyAction =new HotkeyActionListener(type, iFace);

KeyStroke keyStroke = Configuration.getKeystroke(type);

String tooltipTxt = Configuration.getToolTip(type);

InputMap imap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

ActionMap amap = component.getActionMap();

imap.put(keyStroke, tooltipTxt);

amap.put(tooltipTxt, keyAction);

}

}

publicclass MyFrameextends AppIFace{

publicvoid requestFocusOnFirstColumn(){

SwingUtilities.invokeLater(new Runnable(){

publicvoid run(){

setFocusOnColNo(0);

}

});

}

publicvoid setFocusOnColNo(int colNo){

CellEditor ce = table.getCellEditor();

if (ce !=null){

ce.stopCellEditing();

}

int selectRow = getCurrentSelectedRow();

table.setRowSelectionInterval(selectRow, selectRow);

table.setColumnSelectionInterval(colNo, colNo);

table.scrollRectToVisible(new Rectangle(0, table.getRowHeight() * selectRow, 20, table.getRowHeight()));

table.requestFocus();

}

}

At runtime, what I found is this:

When I've selected a non-editable cell on the table and I press a short-cut key to jump to some other column, all is ok and focus goes to the correct cell in another column.

But when I've selected an editable cell and I press the short-cut key, two things happen

1. The selected cell goes into edit mode

2. The focus shifts to the other cell. But the cell in #1 now exits edit mode and focus shifts back to the first cell.

How can I fix this so that the my short-cut keys always work, regardless of whether the selected cell is editable or non-editable.

thanks,

[4913 byte] By [tsca] at [2007-11-27 5:30:46]
# 1
Not sure if it will make a difference buy you could try using the "WHEN_FOCUSED" InputMap.
camickra at 2007-7-12 14:55:20 > top of Java-index,Desktop,Core GUI APIs...