在 Java 中显示 JTextField 事件?

发布于 2025-01-03 19:32:14 字数 217 浏览 3 评论 0原文

我正在实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨小沫ゞ 2025-01-10 19:32:14

虽然使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文