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

标签 java swing

我有一个 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/

相关文章:

java - JPanel在使用延迟时不会实时更新

java - 在 Board (JPanel) 中模拟鼠标点击

java - 将数据加载到组合框

java - 单击 JCheckBox 时添加值

java - 将大 XML 文件拆分为较小的文件

java - Android 服务中调度的 AsyncTask 仅正确执行一次

java - 删除数组中空值的最有效方法是什么。

c# - 如何创建起始索引为 1(而不是 0)的 ArrayList

java - 为什么要在返回之前将 volatile 分配给局部变量

swing - Java SE 二进制崩溃