gpt4 book ai didi

java - 如何禁用按下删除键时的 Windows 蜂鸣声

转载 作者:行者123 更新时间:2023-12-01 11:54:52 25 4
gpt4 key购买 nike

我有一个 java swing 应用程序,每次我删除 jtable 中的一行时,它都会发出蜂鸣声。

有人知道如何防止这种情况发生,或者至少知道是什么原因造成的吗?

最佳答案

从这里:https://www.java.net/node/687490

On Windows, pressing the Alt key moves the keyboard focus to the window menu in the top left corner. This focus is invisible, and it even does not send a "focus lost" event. But if you press and release Alt and then press the up or down arrow, the window menu will show up.

Luckily, it's possible to prevent this functionality of the Alt key:

 addKeyListener( new KeyAdapter() { 
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed code=" + e.getKeyCode());
e.consume();
} } );

e.consume( ) prevents the event to be processed by usual rules. This prevents the Alt key from moving the focus to the window menu, and further alphanumeric keys continue to function as usual. You may want to check the event code and consume only Alt keys, if something else stops working.

关于java - 如何禁用按下删除键时的 Windows 蜂鸣声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28523652/

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