aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with JTextField" Watch "Problem with JTextField" New topic
Author

Problem with JTextField

Anand Kumar Reddy
Greenhorn

Joined: Jul 01, 2008
Posts: 6
Hi,

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) {
x.setSelectionStart(0);
x.setSelectionEnd(x.getText().length());
x.requestFocus();
}

Can some body help me how to solve this problem?


Cheers,
Anand.

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

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?


SCJP, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with JTextField