I have a JTextField that only lets the user enter 20 characters. But the problem is, it doesn't let the user press enter. Here is the code. How can I change it so it will let the user press enter after typing in 20 or less characters? import javax.swing.text.*;
My problem is that when the user presses enter in this JTextField nothing happens. If I set a key listener to listen for VK_ENTER what is the action that I want to happen? Set text and yield focus? The action happens if I move focus off the field. I want it to happen with user pressing enter. I'm not sure how to do it. Any suggestions?
It's unclear what you are saying -- whether or not a JTextField has a custom document has nothing to do with its behavior when you press VK_ENTER. If you want a JTextField to react to enter being pressed, register an ActionListener with the component.