aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes requestFocusInWindow() doesnt work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "requestFocusInWindow() doesnt work" Watch "requestFocusInWindow() doesnt work" New topic
Author

requestFocusInWindow() doesnt work

mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi. is there any other method that needs to be called aside from requestFocusInWindow() because it doesnt work in my case

i system.out the method and it returns true

but if i call isFocusOwner() it returns false which has me baffled since the requestFocusInWindow() returned true, isFocusOwner() should return true but it does not.


Website/Java Games: http://www.chitgoks.com
Tech Blog: http://tech.chitgoks.com
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2226
    
    8
It only works on a component that is displayed in a visible frame.

If you need further help then you need to create a SSCCE (Short, Self Contained, Compilable and Executable, Example Program), that demonstrates the incorrect behaviour.

Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi rob, the bean component is visible.

i called setRequestFocusEnabled(true) and setFocusable(true) to be sure but still no result.

actually, i have a split pane. the left pane contains a jtree while the right contains a panel

when i click an item in the jtree, i called the right panel's requestFocusInWindow() so that the focus would transfer there and any keypress will be detected by that panel.

but ... it does not work. got some ideas?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2226
    
    8
I don't see a SSCCE anywhere!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Like Rob said, post your SSCCE code. Else we are shooting in the dark.
One shot in the dark though. Wrap your calls to request focus inside SwingUtilities#invokeLater.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
hi maneesh, yeah. i will make a short code for this.

i already that invokelater and it didnt work as well.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155


ok so here's the code. when the jtree is clicked via the mouse, the focus should transfer to the panel object. but it doesnt. the system.out shows the jTree1 still has focus even though I called requestFocus(); requestFocusInWindow() doesnt work either.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2226
    
    8
ok so here's the code.


Well, 3 strikes and your out. That is NOT a SSCCE and I'm not going to waste any more time since you aren't willing to do a little work to give us the information we need to solve your problem.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Mark,
I am with Rob here. Please go through the link he provided which explains what SSCCE code is. Posting your SSCCE code will help us help you better.
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
ok. i will recreate a shorter version of my existing code.

the prob seems to stem that the components are in a jsplitpane and transferring focus from the left pane's component to the right pane's component is the issue. will paste the code
mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
i did a workaround instead though

http://tech.chitgoks.com/2009/11/17/requestfocus-any-component-inside-a-jsplitpane/

i simulated a mouse click instead. seems jsplitpane's a "pain" transferring focus programmatically
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

mark chester goking wrote:
i simulated a mouse click instead. seems jsplitpane's a "pain" transferring focus programmatically


No it is not. I don't know the reason why you are not posting your SSCCE. Maybe it is top secret. Maybe something else. I wonder how many people will be helpful to you after this.
Here is my code which works without any dirty fix.

mark goking
Ranch Hand

Joined: Aug 18, 2009
Posts: 155
thank you for your input maneesh
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

mc gox wrote:

Please check your private messages for an important administrative matter.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2226
    
    8
I don't know the reason why you are not posting your SSCCE.


Because he know that someone will spoonfeed the answer anyways!

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Rob Camick wrote:
Because he know that someone will spoonfeed the answer anyways!


Touche'
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: requestFocusInWindow() doesnt work