943,527 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3852
  • Java RSS
Mar 26th, 2008
0

Swing: default button problem

Expand Post »
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:
Java Syntax (Toggle Plain Text)
  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:
Java Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wouterdc is offline Offline
4 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: what is the wrong with Byte constructor which takes int value
Next Thread in Java Forum Timeline: question about JFrame





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC