1> 我在 Jframe 中有一个 JButton。
2> 单击JButton 将打开另一个JFrame 的新实例。
问题是当在上面的 Jbutton 上快速按下某个键时。会打开同一个 JFrame 的两个实例。
我必须打开这些框架。我知道还有其他选项也不使用 Jframes,正如我所读到的。
我设法通过 setMultiClickThreshHold('time in milliseconds') 解决了鼠标双击的问题。但它仅适用于鼠标。
尝试了我在谷歌中找到的其他一些东西,但没有任何效果。 还有其他方法可以解决这个问题吗?
最佳答案
要完全控制操作再次触发的频率/速度,请实现它以在其 actionPerformed 中禁用自身。像这样的东西:
singlePerform = new AbstractAction("DoSomthing") {
@Override
public void actionPerformed(ActionEvent e) {
setEnabled(false);
doSomething();
}
};
JButton button = new JButton(singlePerform);
当可以安全地再次触发 doSomething 时,只需重新启用该操作即可:
singlePerform.setEnabled(true);
关于java - 在 Jbutton 引线上快速按下双键会导致相同的操作两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14456103/