Java Swing:在未选择的 JTabbedPane 面板上更改隐藏 UI 元素时发出声音
我是 Java 新手,所以我很难自己找到这个问题的答案。我正在编写一个 Java 应用程序,并且正在使用 Swing。我不确定它是否相关,但我在 Mac 上使用 Netbeans 作为我的 IDE。
我一直遇到这样的问题:每当我的 Java 程序启动时,就会发出可听见的声音。我追踪到对 JTextField 元素的 setText 方法调用,该元素恰好位于 JTabbedPane 的未选定面板上。如果我将其注释掉,则不会出现声音。
我想这样做的原因是,当选择该面板时,它将显示正确的信息,直到程序启动后我才知道这些信息。
有谁知道为什么会发生这种情况以及如何禁用它?
谢谢!
I'm new to Java, so I'm having a hard time tracking down an answer to this on my own. I'm writing a Java application, and I'm using Swing. I'm not sure if it's relevant, but I'm using Netbeans as my IDE on a Mac.
I've been having this problem where an audible sound would be emitted whenever my Java program was launched. I tracked it down to a setText method call to a JTextField element that happens to be on an unselected panel of a JTabbedPane. If I comment that out, the sound doesn't occur.
The reason I want to do this is so that when that panel is selected, it will appear with the correct info, which I don't know until the program has started up.
Does anyone have an idea as to why this is happening and how to disable it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发问者的评论似乎应该是一个答案,所以这里是:
它与隐藏无关。我不假思索地从事件调度以外的线程中执行此操作。我不知道为什么它会发出蜂鸣声,但是当我正确使用
invokeLater
时,声音就消失了。Questioner's comment seems like it should be an answer, so here goes:
It had nothing to do with being hidden. I was thoughtlessly doing this from a thread other than the event dispatch. I'm not sure why it beeped, but when I properly used
invokeLater
, the sound went away.