I am working on a Java project and need to have a keypress simulate a click on a JTextField. What I\'m looking for is the equivalent of the JButton doClick() method.
If you want the same thing to happen both due to the mouse and a key press, wouldn't it make more sense to have a method called by both? That is, you have a method like fieldClicked
which gets called both by the MouseListener
and by the KeyListener
. This would be easier to debug--less mucking about with events, which can be very confusing--and probably more readable.