mardi 24 juin 2014

In what scenario would consume() restore default behavior?


Vote count:

0




When incorporating the following code in a simple program, it stops the cursor from moving (when using the left/right arrows) when inside a cell of a JTable when in edit mode as expected.



public void keyPressed(KeyEvent e) {
if ( (e.getKeyCode() == KeyEvent.VK_KP_LEFT) || (e.getKeyCode() == KeyEvent.VK_KP_RIGHT)
|| (e.getKeyCode() == KeyEvent.VK_RIGHT) || (e.getKeyCode() == KeyEvent.VK_LEFT) )
{
//Do nothing
e.consume();
}
}
});


Using the same code above to override different behavior in a different program there were unexpected results.


Before incorporating the code, the left/right arrow keys would move to the next cell when in edit mode. After incorporating the code above, the default behavior was restored instead of it disabling the left/right keys as in the basic sample.


Since a sample can't be provided I am wondering in what scenarios would the e.consume() restore default functionality?



asked 35 secs ago






Aucun commentaire:

Enregistrer un commentaire