| | |
Swing: default button problem
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes client code component consumer database draw eclipse ee error event exception fractal free game gameprogramming gis givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javaprojects jmf jni jpanel julia jvm key linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie nextline nls notdisplaying number oracle output print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows





