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


Don Arnett

Joined: Feb 05, 2001
Posts: 18
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();
//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

Joined: Feb 05, 2001
Posts: 18
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.
I agree. Here's the link:
subject: selectALL()
jQuery in Action, 3rd edition