Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selectALL()

 
Don Arnett
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an applet with two TextFields. When the textfield gains focus I want the contents automatically selected & highlighted. I added a focusListener and focusGained method. In the focusGained method I call selectAll().
public void focusGained(FocusEvent event)
{
TextField tf = (TextField)event.getComponent();
tf.selectAll();
//showStatus("selected = " + tf.getSelectedText());
}
The text is being selected but not highlighted on the screen. I mean that visually I don't see a change. But if I call getSelectedText() and display, all of the text is displayed, therefore it is being selected. But the user can't tell because it is not highlighted.
I've even tryed calling repaint() etc.
Any ideas?
 
Don Arnett
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gee, hate to keep answering my own posts, but...
I finally noticed that it did select/highlight the way I expected if I used tab to move focus into a textfield. If I move the focus by clicking in the field with the mouse, the text did not highlight. But this is how the normal HTML input fields work, so all is ok.
I had to add select(0,0) inside the focusLost() to unselect when the field loses focus and now the text fields work just like they did when they were HTML input fields rather than inside an applet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic