Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-2008, 03:58 AM
Member
 
Join Date: Feb 2008
Posts: 3
Iyengar is on a distinguished road
requestFocusInWindow() not working
I am trying to get the initial focus to a Text Filed and use requestFocusInWindow. But for some reason it is not working. Any idea what could be the problem.

Here is the part of the code.

jcrewCodeTextFld_.requestFocusInWindow();
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-19-2008, 07:12 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Look up this method in the Component class api Method Summary section and follow the link to the Method Detail section. It contains a lot of information about how this works. You may have to place the method call after the app is made visible.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-24-2008, 03:35 AM
Member
 
Join Date: Feb 2008
Posts: 3
Iyengar is on a distinguished road
Thanks. This line did the trick
this.setInitialFocus(getMDateFld());
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-02-2009, 06:26 AM
Member
 
Join Date: Jan 2009
Posts: 5
ScottVal is on a distinguished road
I am also having trouble with requestFocusInWindow().

I am creating a JPanel which contains two JPanels.

Let's call the first contained panel "Canvas." It is a customized control.

I want "Canvas" to request the focus, so I call isFocusable() in the constructor.

I'm wanting "Canvas" to get the focus so that it can respond to keyboard input.

I call requestFocusInWindow() whenever the mouse is moved or dragged over the "Canvas," but the method always returns false.

I checked the API docs to make sure I'm doing everything right: setVisible(true); setEnabled(true).

I even tried creating a simplified app which does nothing but request the focus, but even it does not work. It is simply a Frame which calls setVisible(true) and setEnabled(true) and isFocusable() and then requestFocusInWindow(), but even that fails.

Any ideas you have would be appreciated.
-Scott
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-02-2009, 09:04 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Try calling setFocusable(true) on the "Canvas" to get it to accept keyboard input.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-02-2009, 10:20 AM
Member
 
Join Date: Jan 2009
Posts: 5
ScottVal is on a distinguished road
I was already calling setFocusable(true), but it does not accept keyboard input.

When I call requestFocusInWindow(), it returns "false," telling me that the request was denied.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-02-2009, 11:05 AM
Senior Member
 
Join Date: Sep 2008
Posts: 317
Darryl.Burke is on a distinguished road
Just a guess, but you may need to wrap the requestFocusInWindow in a SwingUtilities.invokeLater.

To get better help faster, post a SSCCE that clearly demonstrates the problem. Link: SSCCE : Java Glossary

db
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-02-2009, 06:44 PM
Member
 
Join Date: Jan 2009
Posts: 5
ScottVal is on a distinguished road
Thanks for your response.

Although I didn't use invokeLater as you suggested, your idea jogged my mind to try something.

I was calling requestFocusInWindow() every time the mouse was pressed, moved or dragged over the control.

I created this control in NetBeans as a JPanel Form. I created a keyPressed event within the form.

Here's my new feature: I'm counting the number of accepted and denied requestFocusInWindow() calls.

It turns out the call usually is denied, but it sometimes is accepted, enough to make the keyPress event work.

So, I'm all better now. Thanks. -Scott
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculator not working Renegade85 New To Java 5 03-10-2008 05:27 PM
sendredirect not working ranga Java Servlet 0 02-11-2008 12:48 PM
working with mp3 in java po0oker Advanced Java 1 10-30-2007 10:20 PM
Webservice ain't working? marcelman Networking 0 08-10-2007 04:48 AM
Working With ANT JavaForums Eclipse 0 04-26-2007 10:16 PM


All times are GMT +3. The time now is 02:32 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org