1. Dashboard
  2. Forum
    1. Unerledigte Themen
  3. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team-Mitglieder
    4. Trophäen
    5. Mitgliedersuche
  4. Tutorial Bereich
  • Anmelden
  • Registrieren
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Lexikon
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

[Netbeans API] Problem with WizardDescriptor and Enter in

  • Stack_overflow
  • 2. März 2014 um 13:58
  • Unerledigt
  • Stack_overflow
    3
    Stack_overflow
    Mitglied
    Punkte
    60
    Beiträge
    7
    • 2. März 2014 um 13:58
    • #1

    Hi! ich bin newbie in Netbeans. Weiß jemand vielleicht, wie ich WizardDescriptor durch Enter Taste schließen kann. ich habe vieles probiert. Es geht aber leider nicht. :frowning_face: ich habe nur ein Page auf Wizard. so Finish Button wird aktiv, sobald Dialog geöffnet wird. folgenden habe ich bisher probiert. Lg

    Code
    [COLOR=#006600][FONT=Courier]Action actionListener = new AbstractAction() { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            public void actionPerformed(ActionEvent actionEvent) { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                wizardDescriptor.doFinishClick(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            } [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        }; [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]        KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        InputMap inputMap = ((JButton) wizardDescriptor.getOptions()[2]).getInputMap(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        inputMap.put(enter, ACTION_KEY); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        ActionMap actionMap = ((JButton) wizardDescriptor.getOptions()[2]).getActionMap(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        actionMap.put(ACTION_KEY, actionListener); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        ((JButton) wizardDescriptor.getOptions()[2]).setActionMap(actionMap); [/FONT][/COLOR][COLOR=#333333][FONT=Verdana]
    [/FONT][/COLOR]
    Alles anzeigen
    Code
    [COLOR=#006600][FONT=Courier] Component comp = iterator.current().getComponent(); [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]        if (comp instanceof JComponent) { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            rootPane = ((JComponent) comp).getRootPane(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            System.out.println("I was here 1!"); [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]        } [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]rootPane.registerKeyboardAction(new ActionListener() { [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]         @Override [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]         public void actionPerformed(ActionEvent e) { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]         wizardDescriptor.doFinishClick(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]         } [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]         }, "Enter", [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]         KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); [/FONT][/COLOR][COLOR=#333333][FONT=Verdana]
    [/FONT][/COLOR]
    Alles anzeigen
    Code
    [COLOR=#006600][FONT=Courier] if (rootPane != null && rootListener == null){ [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            // Set listener on root for cases some needless button [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            // would like to become default one (the ones from superclass). [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            rootPane.addPropertyChangeListener(WeakListeners.propertyChange( [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                rootListener = new PropertyChangeListener() { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                    public void propertyChange(PropertyChangeEvent evt) { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                        if ("defaultButton".equals(evt.getPropertyName())) { // NOI18N [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                            Object newValue = evt.getNewValue(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                            if ((newValue != ((JButton) wizardDescriptor.getOptions()[1])) && (newValue != ((JButton) wizardDescriptor.getOptions()[2]))) { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                                RequestProcessor.getDefault().post(new Runnable() { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                                    public void run() { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                                        updateDefaultButton(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                                    } [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                                }); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                            } [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                        } [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                    } [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                }, [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                rootPane [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            )); [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]         } [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]private void updateDefaultButton() { [/FONT][/COLOR]
    
    
    
    
    [COLOR=#006600][FONT=Courier]        if(rootPane == null) [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            return; [/FONT][/COLOR]
    
    
    [COLOR=#006600][FONT=Courier]        final WizardDescriptor.Panel panel = iterator.current(); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        if ((panel instanceof WizardDescriptor.FinishablePanel) [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]                && ((WizardDescriptor.FinishablePanel) panel).isFinishPanel()) { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            rootPane.setDefaultButton(((JButton) wizardDescriptor.getOptions()[2])); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        } else { [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]            rootPane.setDefaultButton(((JButton) wizardDescriptor.getOptions()[1])); [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]        } [/FONT][/COLOR]
    [COLOR=#006600][FONT=Courier]    } [/FONT][/COLOR][COLOR=#333333][FONT=Verdana]
    [/FONT][/COLOR]
    Alles anzeigen


    You don't have a second chance to make a first Impression! Just take a chance!

  • Maximilian Rupp 27. Dezember 2024 um 00:26

    Hat das Thema aus dem Forum Programmieren nach Entwicklung verschoben.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!

Benutzerkonto erstellen Anmelden

Rechtliches

Impressum

Datenschutzerklärung