wood burning stoves 2.0*
The moose likes Applets and the fly likes Focus on textbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Focus on textbox" Watch "Focus on textbox" New topic

Focus on textbox


Joined: Aug 01, 2000
Posts: 16
Hello guys
I want the cursor to be on a specific textbox when my
applet loads.How do I do that ??
Also, can I set the focus on a text box on generation of some event
Thanx in anticipation

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Sure... just use the requestFocus() method of Component( which TextBox(?!?!) (I assume you mean TextField or TextArea.) inherits from.) You can do this when you first display it, or in response to an event... Just remember, as the API doc on this method states, "The component must be visible on the screen for this request to be granted."
P.S. - Some people on here might bug you about this, too... But JavaRanch's naming policy states that you have to have a name with a space in it... Not being picky... it is just the rule...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Focus on textbox
Similar Threads
set focus in textbox inside sliding bar
Control transfer between Two Textareas
when focus to select drop down focus go to textbox, how do?\
question on changing focus
How do you show a component that has focus?