Is there a JOptionPane Listener?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 12
Reputation: bsunkel is an unknown quantity at this point 
Solved Threads: 0
bsunkel bsunkel is offline Offline
Newbie Poster

Is there a JOptionPane Listener?

 
0
  #1
Sep 6th, 2005
Hi all,

I have a JOptionPane with a YES button and a NO button. All I want to do is be able to press the left or right button on the keyboard to change the focus on the buttons. By using the mouse it works. Is there some kind of Listener I can use?

Here is my code :

====================================================

int response = JOptionPane.showConfirmDialog(null,"Are you sure you want to exit","Exit?",

JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE);

if(response == JOptionPane.YES_OPTION){
System.exit(1);
}else {
//do nothing
}

=====================================================
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Is there a JOptionPane Listener?

 
0
  #2
Sep 6th, 2005
You could TRY a keylistener but I'm not sure that'll work out exactly like you want. There should already be a mechanism built in that changes components when tab is pressed. I would stick to that if I were you.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 765
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Is there a JOptionPane Listener?

 
0
  #3
Sep 7th, 2005
From Windows, usually hitting TAB will change focus between components. If you must use the arrow keys, you could add a KeyListener which changes the focus to the button components. I would probably make a new class and extend the JOptionPane
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC