在 Java 中显示 JTextField 事件?
我正在实现 JTextField 的专用版本,并希望将其打包到自己的 bean 中。到目前为止,该 bean 工作得很好。这是我的问题:
如何检测 JTextField 何时显示?这样我就可以在每次显示字段时初始化一些图形内容。
ShowComponent 事件对我不起作用。 FocusGained 和 FocusLost 效果很好。
希望有人知道这个问题的解决方案。
I'm implementing a specialized version of JTextField and want to pack it into an own bean. The bean works pretty fine so far. Here's my question:
How can I detect when the JTextField is shown? So that I can init some graphical stuff everytime the fields are shown.
The ShowComponent event does not work for me. FocusGained and FocusLost works just fine.
Hope there's somebody who knows the solution to this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 isShowing() 方法吗?
http://docs.oracle .com/javase/7/docs/api/java/awt/Component.html#isShowing%28%29
Can you use the isShowing() method?
http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html#isShowing%28%29
虽然使用 ComponentListener 并在其 componentShown 中执行操作直观上似乎是可行的方法,但它没有帮助:当组件的可见属性更改时它会触发。该属性默认为 true(即使尚未添加到屏幕上显示的任何容器中),因此在显示时不会触发任何内容。
相反,请使用 AncestorListener 并执行其祖先添加中所需的操作。
While using a ComponentListener and doing stuff in its componentShown intuitively seems to be the way to go, it doesn't help: it fires when the component's visible property is changed. That property is true by default (even if not yet added to any container showing on the screen), and consequently nothing fired on showing ..
Instead, use an AncestorListener and do what's needed in its ancestorAdded.