开发者

How can I listen for keyboard input? such as arrow keys?

what is the easiest way to listen for key presses from the user? Specifically I am writing an image viewer program that uses a JFileChooser to select images and on the left side, a JList that shows the contents of the director. I would like to make the arrow ke开发者_StackOverflowts (left/right) move to the next/previous file.

Thank you in advance.


It sounds like you need a KeyListener. The linked tutorial also talks about focus, which will be important to ensure your key events are trapped by the right handler.


Swing was designed to use Key Bindings.

In fact a JList already supports the up/down keys to move to the next item in the list. You can easily map these Actions to the left/right keys.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜