| | |
Swing: default button problem
![]() |
•
•
Join Date: Feb 2008
Posts: 4
Reputation:
Solved Threads: 0
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:
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:
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
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)
getRootPane().setDefaultButton(panel.getDefaultButton());
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)
public void keyReleased(KeyEvent evt) { if(evt.isActionKey()) btnSelect.doClick(); }
default button is still executed. Is their anonther way to solve this problem?
Thanks in advance
![]() |
Similar Threads
- wierd gui/constructor problem (Java)
- Delete button not working on my Java GUI Inventory (Java)
- need help to solve this problem (Java)
- custom cursor (Java)
- Source Code that don't work? (Java)
- IE Emergency: Cannot find server or DNS Error (Web Browsers)
- Aurora and more (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: what is the wrong with Byte constructor which takes int value
- Next Thread: question about JFrame
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





