Swing: default button problem

Reply

Join Date: Feb 2008
Posts: 4
Reputation: wouterdc is an unknown quantity at this point 
Solved Threads: 0
wouterdc wouterdc is offline Offline
Newbie Poster

Swing: default button problem

 
0
  #1
Mar 26th, 2008
Hello,

I have a problem setting a default button with Java Swing.
I have a JFrame containing one JPanel and one JMenuBar. This panel contains some textfields,
a list and some buttons. At the button there is one button which has to be the default
button. I also gave the JPanel a method getDefaultButton which returns the button which
I want to be the Default Button. So in the contructor of the JFrame I wrote:
  1. getRootPane().setDefaultButton(panel.getDefaultButton());
This works all correct, but I also want that in one case (If the focus belongs to a certain
textfield) there is a different default button. So I wrote a KeyListener for this textfield
and implemented the method KeyReleased like this:
  1. public void keyReleased(KeyEvent evt) {
  2. if(evt.isActionKey())
  3. btnSelect.doClick();
  4. }
When the focus belongs to this textfield and I press enter the
default button is still executed. Is their anonther way to solve this problem?

Thanks in advance
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