wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Setting the cursor in a text field after clicking a button? 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 "Setting the cursor in a text field after clicking a button?" Watch "Setting the cursor in a text field after clicking a button?" New topic
Author

Setting the cursor in a text field after clicking a button?

Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Hello I have a JButton programmed in a SWing GUI that when I click it, it will take the score and put it into a JLabel somewhere else. The thing is when I click the JButton the cursor doesn't reset back to the JTextField. How would I go about doing that?

Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Swing? HTML? Other?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Bear Bibeault wrote:Swing? HTML? Other?


I'm sorry about that, I am using a Swing GUI with JButton and JTextField
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
textfield.requestFocusInWindow()

but it might be simpler to have
button.setFocusable(false)
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
Michael Dunn wrote:but it might be simpler to have
button.setFocusable(false)


Then you can't use the keyboard and tab to the button.

A GUI should support keyboard and mouse UI.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Rob Camick wrote:
Michael Dunn wrote:but it might be simpler to have
button.setFocusable(false)


Then you can't use the keyboard and tab to the button.

A GUI should support keyboard and mouse UI.


Yeah... I am able to type in a number and press enter on the keyboard, and I am able to click the button... I like to personally press enter, but my buddy likes to click calculate... He said he would like the cursor to be automatically set to the JtextField... I thought that using some sort of focusable, but I'm not really sure how they work...
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Michael Dunn wrote:textfield.requestFocusInWindow()

but it might be simpler to have
button.setFocusable(false)



.requestFocusInWindow() worked thanks! So this basically keeps the cursor in the window at all times?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Jay Orsaw wrote:.requestFocusInWindow() worked thanks! So this basically keeps the cursor in the window at all times?

The method does what the API says. You have read the API, haven't you?


luck, db
There are no new questions, but there may be new answers.
 
 
subject: Setting the cursor in a text field after clicking a button?
 
Similar Threads
refreshing the page when radio button clicked
wait cursor
Change Image Of Mouse Cursor
NX: How to get the new value from the cell of the JTable ?
How to set the cursor to default ?