Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

java - How to turn off a key listener in NetBeans wizard panels?

I developed a simple plugin for NetBeans IDE. I have a little problem with default key event on TopComponenet of Wizard panel:

For example:

I have a wizard with 3 steps. In second step I have a JTextField where user put some values and after that appear a JList below this text field. Everything is okay until user choose a some value from list and than press key ENTER then my panel goes to next Step 3. I attach a key listener to list something like:

list = new JList(new PackagesListModel());
list.addKeyListener(new KeyAdapter() {
    @Override
    public void keyReleased(java.awt.event.KeyEvent evt) {
        int keyCode = evt.getKeyCode();
        if(keyCode == KeyEvent.VK_ENTER){
            JList list = (JList)evt.getSource();
            Object selectedPackage = list.getSelectedValue();
            typePackageField.setText((String)selectedPackage);
        }
    }
});

But this listener probably is invoking after default listener of TopComponenet on wizard. How can I prevent moving user to next step using ENTER key?

I don't want this action (when user press ENTER then they go to the next step).

UPDATE:

Forwarding to Kraal answer:

Problem is that i dont know where i can lookking for a JButton Next (to shuting down a listener). It sound strange but how i wrote. Im using a Netbeans Plaform WizzardDescriptor to generate a Wizzard (with 3 steps) . WizzardDescriptor is from package:

  org.openide.WizardDescriptor; // Dialogs API

i puted to him a 3 instances of panels: WizardDescriptor.Panel from same package:

  org.openide.WizardDescriptor // Dialogs API

it looks like:

    panels = new ArrayList<>();
    panels.add(new LayoutWizardPanel1(selectedLayout));
    panels.add(new LayoutWizardPanel2(selectedLayout));
    panels.add(new LayoutWizardPanel3(selectedLayout));
    WizardDescriptor wiz = new WizardDescriptor(new WizardDescriptor.ArrayIterator<>(panels));

After this will generated something like:

enter image description here

in my program i have access to WizardDescriptor

 http://bits.netbeans.org/dev/javadoc/org-openide-dialogs/org/openide/WizardDescriptor.html
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure but if you know which JComponent causes this behaviour, try this:

suspectedComponent.getInputMap().put(KeyStroke.getKeyStrokeForEvent(KeyEvent.VK_ENTER),"none");

To check which keystrokes are bound on a JComponent:

suspectedComponent.getInputMap().keys()

Or in the parent InputMap:

suspectedComponent.getInputMap().getParent().keys()

See the docs for InputMap for details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...