aspose file tools*
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
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: 61766
    
  67

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: 2227
    
    8
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: 4664
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting the cursor in a text field after clicking a button?