I have a text field and mapped the enter key with an action to that text field. After enter key press, How can I remove that key event for press enter key in the text field?
Asked
Active
Viewed 919 times
-1
-
Insert your code and/or example – FabioBranch Mar 09 '17 at 09:49
-
1Why? `JTextField` already responds to Enter via the `ActionListener` and `Action` APIs – MadProgrammer Mar 09 '17 at 09:58
-
I think you have misunderstood my question. – Srishiyamalan Ratnavel Mar 09 '17 at 10:17
-
I have two separate components, I can only use this method to access the component reference. XXXmodule.getView() : JComponent, I want to add enter key listener to components inside the parent component. How can it possible? – Srishiyamalan Ratnavel Mar 09 '17 at 10:21
-
1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) Tip: Add @MadProgrammer (or whoever, the `@` is important) to *notify* the person of a new comment. 3) This sounds like an XY problem. See [What is the XY problem?](http://meta.stackexchange.com/q/66377) But I agree with previous comment .. 'Why?'. – Andrew Thompson Mar 09 '17 at 10:49
-
@SrishiyamalanRatnavel No, you don't want to add a key listener, you want to use an ActionListener or Action for text fields – MadProgrammer Mar 09 '17 at 18:29
1 Answers
0
After enter key press, How can I remove that key event for press enter key in the text field?
textField.removeActionListener(...);

camickr
- 321,443
- 19
- 166
- 288