gpt4 book ai didi

Java Swing 按键事件

转载 作者:行者123 更新时间:2023-12-01 05:19:10 25 4
gpt4 key购买 nike

我正在为我的 JFrame 使用预定义的继承焦点遍历类

我已经为我的一个按钮定义了按键事件,并通过按 Tab 键选择 jTabbed Pane 的其他选项卡进行了一些操作。此按钮仅对 Tab 键不响应。

   int index=1;


if(evt.getKeyCode() == KeyEvent.VK_TAB)
{

// wrap around

if(evt.isShiftDown())
{

KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent();

}
else
{
System.out.print("Shift Up");

KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();
jtabPaneProducts.setSelectedIndex(index);
}
}

请指导我如何让 jbutton 除了焦点遍历功能之外还可以响应 TAB 键按下。

最佳答案

您应该有兴趣阅读How to Write a Key Listener :

Alternatively, you can use the KeyEventDispatcher class to pre-listen to all key events. The focus page has detailed information on the focus subsystem.

因此:Interface KeyEventDispatcher

关于Java Swing 按键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10696113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com