• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Focus Using Mouse

 
yousef mo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I have a frame set up that has a JTree on one side and a JPanel on the other side which are separated using the JFrame's BorderLayout. My issue is that when I type something on my keyboard it sends the keystrokes to both components. I think this is a focus issue.

I want to be able for the keyboard to focus on one component at startup and then switch back and forth only when the mouse is clicked on a component.

I have spent a good amount of time looking at the focus tutorials and have not come across a solution. If someone here could help me solve this issue I would greatly appreciate it.

Thanks.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to be able for the keyboard to focus on one component at startup and then switch back and forth only when the mouse is clicked on a component.
I explored this in/with the app below it seems to work according to what you want with the exception that the tab key also shifts the focus back and forth. Maybe you can alter it to show the trouble you're having.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!