File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extending JPanel and Focus

 
Philip Dush
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I've created a new class and called it gamePanel. It extends JPanel. I've added this panel to a frame, along with some buttons, in my main method. Essentially, by pressing buttons, it takes the focus off the panel which doesn't allow my key listeners (which were added to the panel) to work. Because gamePanel is a custom panel, and not a normal JPanel, using the method .requestFocusInWindow() doesn't work. so I made a method for my gamePanel object that when called upon will invoke the other method to give the focus back to the panel. However, it gives an error at the point in which my gamePanel object calls the method. So my ultimate question is, how can I get this working, or how can i return focus to my object?

If you need it, heres my code. Its long, and you should only need to look at lines 143 in "test" and line 21 in "gamePanel".


gamePanel class:

 
Michael Dunn
Ranch Hand
Posts: 4632
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeyBindings
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To elaborate, key bindings.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic