• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with JTextField

 
Anand Kumar Reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Steven Wall
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic