Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

arrow keys functionality  RSS feed

 
Ananth Ram
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Please find the code below. I need to use the arrow keys when the user moves up and down in a table and I am able to do so, but when we move up, the column does not become editable.

Any advise on how to tweak the keyevent stuff.

public class ItLevel extends JPanel implements KeyListener
{

JTable tblItem = new JTable();

private void jbInit() throws Exception
{

tblItem.setDragEnabled(true);
tblItem.setTransferHandler(tblSortTransHandler);
tblItem.addKeyListener(new KeyAdapter()
{
public void keyReleased(KeyEvent e)
{
tblItem_keyReleased(e);
}
});

}

public void tblItem_keyReleased(KeyEvent e)
{

enableUpOrDownButtons(this.tblItem, this.btnUp, this.btnDown);
if (e.getKeyCode() == e.VK_ENTER || e.getKeyCode() == e.VK_TAB)
{
this.showCorrectLocationInDropdown();
// populate the drop downs
}

if (tblItem.getSelectedRow() >= 0)
{
switch (tblItem.getSelectedColumn())
{
case ITEM_DESC_TBLPOS:
if(e.getKeyCode() != e.VK_ENTER && e.getKeyCode() == e.VK_TAB)
{
tblItem.editCellAt(tblItem.getSelectedRow(), tblItem.getSelectedColumn());
txtTableSelectStrings.requestFocus();
}
break;
}
}
}
}

Thanks,

Ananth
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!