This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How we can set focus? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How we can set focus?" Watch "How we can set focus?" New topic
Author

How we can set focus?

Muhammad usman shad
Ranch Hand

Joined: Jan 06, 2010
Posts: 30
I have developed a program in which when i click on a button,
A new text field is created...

Suppose i clicked on the button 10 times,
10 text fields will be created...

The cursor lies on the very first textfield,
I want that cursor should be on the last field created...

How is it possible...
I think that this is the case of focus...

Please guide me!!!
Kuldip Shetty
Ranch Hand

Joined: Jan 07, 2010
Posts: 39

document.forms[0].field.focus()

Here "field" is the name of the text field. Using this you can set focus to particular field in the form.

Kuldip
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
The method with the join-the-dots and focus() looks incorrect. You probably want to invoke this method, but I am not sure it will guarantee to take the focus.

Moving to our GUIs forum.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2152
    
    7
Campbell Ritchie wrote: You probably want to invoke this method, but I am not sure it will guarantee to take the focus.


Actually, the API, "strongly encourages" you to use the requestFocusInWindow() method.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
Thank you. That will teach me to quote without reading it
 
 
subject: How we can set focus?
 
Similar Threads
JTextField Focus issue
Focus / Action Listener combo question
swng text field issues
General question on validating textbox entries using the .blur event
Remove focus