This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes ask some questions about FocusListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ask some questions about FocusListener" Watch "ask some questions about FocusListener" New topic
Author

ask some questions about FocusListener

cat cater
Ranch Hand

Joined: Jun 06, 2005
Posts: 39
focusGained and focusLost hasnot been triggered.why? Some who can tell me how to do.Thanked first.

code:
class JBasePanel extends JPanel{

public JBasePanel(){
//add JMyPanel
add(new JMyPanel());

}

}

class JMyPanel extends JPanel{

................// variable

public JMyPanel(){
................ //some initialize code
//add Event
this.addFocusListener(new FocusListener(){

public void focusGained(FocusEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null,"have")
}

public void focusLost(FocusEvent e) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null,"havn't");
}

});

}

}
cat cater
Ranch Hand

Joined: Jun 06, 2005
Posts: 39
Your enthusiasm is driving me.
thanks. thansks!
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
JPanels by default are focusable, so either override isFocusable or call setFocusable:
1. I'm using System.out, not dialogs, since a dialog's display would cause
and endless triggering of focus gained and lost!
2. Why do you want a JPanel to be focusable? It's usually user-input
controls, not containers that can get focus.


There is no emoticon for what I am feeling!
cat cater
Ranch Hand

Joined: Jun 06, 2005
Posts: 39
Uses setFocusable (true) the method not to achieve the anticipatedeffect.
focusGained and focusLost hasnot been triggered.JMyPanel is joined to other vessel in.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Sincd my example does work, I suggest you post a minimal complete program demonstrating your problem.
cat cater
Ranch Hand

Joined: Jun 06, 2005
Posts: 39
First,I thank your help extremely
But JPanel only then time obtains the focal point the opportunity. I want to press the Jpanel and get focal.. JButton and other input components May duplicate obtains the focal point. Has any method to be possible to change this kind of aspect?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I *really* didn't understand that last post. Again, if you could post a
minimal example program that demonstrates your problem, that would go a
long way in helping forums members help you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ask some questions about FocusListener