我怎样才能听到在Java中按下/键入的TAB键? [英] How can I listen to a TAB key pressed/typed in Java?

查看:457
本文介绍了我怎样才能听到在Java中按下/键入的TAB键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private void jTextField1KeyPressed(java.awt.event.KeyEvent evt)
{
//不能捕获我的TAB?
System.out.print(evt.getKeyChar());




$ b $ p
$ b

在java中,gui最简单的方法是捕获tab键而不使用焦点侦听技术?

解决方案

VK_TAB 是选项卡常量。 p>

然而:没有Tab键或键释放的事件被键事件侦听器接收到。这是因为焦点子系统消耗焦点遍历键,如Tab和Shift Tab。



请参阅: http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html



为了解决这个问题,将以下内容应用于触发按键事件的组件(例如TextArea):

使用这个方法,你必须明确地处理焦点遍历。你可以使用这个方法来处理焦点遍历。或者,可以使用 KeyEventDispatcher 类预先听取所有关键事件。

    private void jTextField1KeyPressed(java.awt.event.KeyEvent evt)
    {
        //cant capture my TAB?
        System.out.print(evt.getKeyChar());

    }

What is the simplest way in an java gui to capture the tab key without doing using the focus listening technique?

解决方案

VK_TAB is the tab constant.

However: No Tab key-pressed or key-released events are received by the key event listener. This is because the focus subsystem consumes focus traversal keys, such as Tab and Shift Tab.

See: http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html

To solve this, apply the following to the component that is firing the key events (e.g., the TextArea):

.setFocusTraversalKeysEnabled(false)

Using this method, you must then handle focus traversal explicitly. Alternatively, the KeyEventDispatcher class can be used to pre-listen to all key events.

这篇关于我怎样才能听到在Java中按下/键入的TAB键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆