File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Problem with JTextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with JTextField" Watch "Problem with JTextField" New topic

Problem with JTextField

Anand Kumar Reddy

Joined: Jul 01, 2008
Posts: 6

When i enter some text into my JTextField, the first character gets selected and will be over written with the second character. i.e., i want to enter -5, but, when i type '-' it gets selected and when i type '5', this over writes the '-' and only '5' remains in the text field.

i tried the following code to fix this, but, is not working....

JTextField x = (JTextField) getEditorComponent();
if (null != x) {

Can some body help me how to solve this problem?


Reach for the sky.. even if you have to stand on cactus!
Steven Wall

Joined: Nov 04, 2007
Posts: 22
Where is the code you posted located? Is it in an ActionListener registered with the JTextField? I haven't tested it, but it looks like that code would cause the behavior you are describing. Have you tried removing that code?

I agree. Here's the link:
subject: Problem with JTextField
It's not a secret anymore!