当我三次单击 JTree 节点时,为什么文本未被选中或不可编辑?

发布于 2024-11-09 10:41:21 字数 277 浏览 4 评论 0原文

我有一个 JTree,我已将其配置为可编辑。当我三次单击节点以编辑底层文本字段时,它会被绘制,但文本未被选中且不可编辑。我成功编辑节点的唯一方法是导航到另一个应用程序,然后返回到 Java 框架。就好像第一次尝试编辑文本字段时没有正确接收焦点一样。

有谁知道为什么我会看到这种行为? JTree 启用了拖放功能,还添加了一个 MouseListener 来处理弹出菜单。这些是否会与编辑/焦点发生冲突?

我正在使用最新的 Java 6u25 JDK 在 Fedora 14 上运行。

I have a JTree that I have configured to be editable. When I triple click on the node to edit the underlying text field, it is drawn but the text is not selected and is not editable. The only way I can edit the node successfully is to navigate to another application and then back to the Java frame. It is as if when first trying to edit the text field is not receiving focus properly.

Does anyone know why I might be seeing this behaviour? The JTree has drag and drop enabled and also a MouseListener added to handle popup menus. Could these conflict with editing/focus somehow?

I am running on Fedora 14 using the latest Java 6u25 JDK.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

也只是曾经 2024-11-16 10:41:21

JTree 启用了拖放功能,还添加了一个 MouseListener 来处理弹出菜单。这些是否会与编辑/焦点发生冲突?

删除该代码,看看会发生什么!

这就是创建 SSCCE 的目的。从 JDK 中的基本代码开始,看看它是如何工作的。然后,假设它正常工作,您添加自定义代码。当它停止工作时,您已经隔离了问题所在,然后也许我们可以提供帮助。

The JTree has drag and drop enabled and also a MouseListener added to handle popup menus. Could these conflict with editing/focus somehow?

Remove that code and see what happens!

That is the point of creating a SSCCE. Start with basic code from the JDK to see how it works. Then, assuming it is working you add your custom code. When it stops working, you've isolated where the problem is and then maybe we can help.

吃素的狼 2024-11-16 10:41:21

我找到了问题的原因。

我的应用程序有一个登录框架,当主框架打开时该登录框架会隐藏。登录框架中的错误意味着即使框架已隐藏,文本字段也会窃取焦点。这会导致 JTree 上的文本字段获得编辑焦点时出现问题。

I found the cause of the problem.

My application has a login frame that is hidden when the main frame is opened. A bug in the login frame meant that a text field was stealing the focus even though the frame had been hidden. This then caused problems with the text field on the JTree getting the focus on edit.

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