aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Extending JPanel and Focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Extending JPanel and Focus" Watch "Extending JPanel and Focus" New topic
Author

Extending JPanel and Focus

Philip Dush
Greenhorn

Joined: Feb 14, 2012
Posts: 1
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

Joined: Jun 09, 2003
Posts: 4632
KeyBindings
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

To elaborate, key bindings.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extending JPanel and Focus
 
Similar Threads
problem with label
Regarding Action and KeyEvents
How can I diplay and Applet on a swing application?
calling another GUI class
JFrame won't repaint...