wood burning stoves 2.0*
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?

It is sorta covered in the JavaRanch Style Guide.
subject: Problem with JTextField
Similar Threads
How to disable selection in a JTextField?
Font in JTextComponent
JTextField focus problem ( urgent !!!!!!)
Passing data between JFrame & JDialog
JTextField/Reading Content