Hello everyone,
I have my code that is supposed to append an empty row to a table at runtime when a user presses the enter button.
The code is working fine.
here is the code if it helps:
table.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
//some code should come right over here
dtm.addRow(new Object[]{"", ""});
}
}
@Override
public void keyReleased(KeyEvent e) {
}
@Override
public void keyTyped(KeyEvent e) {
}
});
}
The problem is: The row is being added when the user presses the enter button despite which cell/row/column has the focus. I mean its doing everytime the enter button is hit.
This is not what i want. I want it to do that ONLY when focus is in the LAST cell of the LAST row in the table.
I will add an image to show where i want this behaviour to happen when the enter button is hit.
How do i get this done?
I appreciate any idea on this issue. thank you in advance.