How do you simulate a click on a JTextField? Equivalent of JButton doClick()?

前端 未结 4 2050
清歌不尽
清歌不尽 2021-01-16 20:19

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.

4条回答
  •  温柔的废话
    2021-01-16 20:59

    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.

提交回复
热议问题