I have a Component with a KeyListener. When the user types a key, say x, a
sorted JList in a JDialog shall pop up and immediately select the first X
entry.
How can I do that? I have already added a KeyListener that listens for a
typed char and pops up the dialog with the list. But now, I have to
propagate the key to the list so that it selects the right entry,
according to what the user has typed.
sth like this:
addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent e) {
dialogWithJList.setVisible(true);
// now sth like:
dialogWithJList.getList().fireKeyPressed(e)
}
});
Maybe I could loop over the elements in the list and get the index of the
first X entry and select it.
But there should be a way to just bring the keyEvent that the user has
generated, forward to the JList.
thanks
Andi
Andreas Schmidt - 21 Nov 2003 19:25 GMT
> I have a Component with a KeyListener. When the user types a key, say x,
> a sorted JList in a JDialog shall pop up and immediately select the
[quoted text clipped - 14 lines]
> }
> });
It should be dispatchEvent, right? It's supposed to dispatch the keyEvent
to the JDialog. But it does not work
dialogWithJList.dispatchEvent(new KeyEvent(
dialogWithJList,
e.getID(),
e.getWhen(),
e.getModifiers(),
e.getKeyCode(),
e.getKeyChar()
));
Why? What can I do?