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. 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