This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Spark in Action and have Jean-Georges Perrin on-line!
See this thread for details.
Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

MyKeyListener won't listen to me

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a desktop application with a JFrame holding a JPanel depicting all sorts of lines and circles.

I can click on the JPanel and call forth all kinds of functionality with my own MyMouseListener,
however instead of just leftClick and rightClick,
I'd like to do Ctrl + LeftClick or 'A' + RightClick to expand functionality.

MyMouseListener works just fine. However MyKeyListener takes no notice of when I use the keyboard.
JPanel is a JComponent, so why doesnt it react to keyboard usage?
Am I on the wrong track?



 
Marshal
Posts: 69738
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at this thread from last week, where somebody else had a similar problem. If you follow the tutorials link in my first post, it tells you about key listeners, and says something about the Component having to be focusable.
That may be your problem.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell, this setFocusable(...) was new to me.

I added this in the ctor and now it runs just fine.

 
Campbell Ritchie
Marshal
Posts: 69738
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
It appeared to be what happened last week, again.

BTW: Abbreviations like ctor can be difficult to understand.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic