Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

selectALL()

 
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.
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic