[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

setDefaultButton on Individual Jpanels that are part of a Wizard

Posted on 2006-05-19
6
Medium Priority
?
410 Views
Last Modified: 2010-03-31
Hello experts

I have a number of Java classes which extend the JPanel with next , prev, apply, etc buttons on them. All of these classes are part of a Wizard. The wizard knows what class to call whenever a button is pressed.

The Question i want to ask is how do I set the Default button on the "Next" button on each of the individual classes wheneve the enter key is pressed.

I cannot change the component type as it is tightly coupled so the soln needs to be based on what I have.

Cheers
0
Comment
Question by:vishalchavda
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 16719445
panel.getRootPane().setDefaultButton(button);
0
 

Author Comment

by:vishalchavda
ID: 16732388
The suggestion:
panel.getRootPane().setDefaultButton(button);
will only set the default button for the current dialog in the wizard. I want to set the default button for all the dialogs within the wizard when they get displayed.
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16733191
panel.getRootPane().setDefaultButton(button);
will set the default button for the component that you have specified
if you want it for all panels, simply call this method on all of them

or try this second solution

            Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
                  public void eventDispatched(AWTEvent event) {
                        if(event instanceof KeyEvent) {
                              KeyEvent ke = (KeyEvent) event;
                              if( ke.getKeyCode() == KeyEvent.VK_ENTER ) {
                                    switch(ke.getID()) {
                                          case KeyEvent.KEY_RELEASED:
                                                System.out.println("Enter Released");
                                                break;
                                          case KeyEvent.KEY_PRESSED:
                                                System.out.println("Enter Pressed");
                                                break;
                                          case KeyEvent.KEY_TYPED:
                                                System.out.println("Enter Typed");
                                                break;
                                    }
                              }
                        }
                  }
            }, AWTEvent.KEY_EVENT_MASK);

simply add this code to your application. whenever enter is pressed you will be notified
0
 

Author Comment

by:vishalchavda
ID: 16750347
This wont work for me
but i have solved the problem by passing the default button from the individual wizard components and as this is also in the main GUI i can get the rootpane from there and set the default button.

thanks any way
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 16958015
PAQed with points refunded (125)

CetusMOD
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question