Java Swing:如何在TreeListeners:valueChanged之前调用stopCellEditing()? [英] Java Swing : How to invoke stopCellEditing() before TreeListeners:valueChanged?

查看:253
本文介绍了Java Swing:如何在TreeListeners:valueChanged之前调用stopCellEditing()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这些先前问题的后续内容:

This is a follow-up to these earlier questions:

  • How to stop editing with DefaultCellEditor when a separate JBtton is pressed
  • Sun Bug 4724980: JTable: Add API to control what happens to edits when table loses focus.

当我使用terminateEditOnFocusLost属性时,如下所示,当表格失去焦点时,我的CellEditor会正确停止

When I use the terminateEditOnFocusLost property, like below, my CellEditor correctly stops editing when the table loses focus:

jtable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

它也可以与我的JButtons一起使用.在处理按钮按下动作之前,为TableCellEditor 调用了stopCellEditing()方法.但是当我将其与JTree一起使用时,并且树的选择发生了变化,TreeSelectionListener.valueChanged方法被称为 before stopCellEditing().

It also works with my JButtons. The stopCellEditing() method is called for my TableCellEditor before the button press action is processed. But when I use it with a JTree, and the tree selection changes, the TreeSelectionListener.valueChanged method is called before stopCellEditing().

有人知道是否有一种方法可以强制首先调用stopCellEditing(),或者我是否应该为此问题做出一些解决方法?

Does any one know if there is a way to force stopCellEditing() to be invoked first, or should I just make up some work-around for this issue?

推荐答案

JTreeSwing中没有相似的客户端属性. 但是SwingXSwingX的派生类,它是SwingX的派生类:invokeStopEditing.

JTree does not have similar client property in Swing. But JXTree, a derived class from JTree, in SwingX does: invokeStopEditing.

如果您不能使用SwingX,则始终可以查看JXTree的源代码,并查看此StopEditing机制的工作原理:

If you can't use SwingX, you can always look at the source code of JXTree and see how this StopEditing mecanism works: JXTree SwingX 1.0 API Documentation and Javadoc (go to Source tab)

特别是从974行开始,创建了一个侦听器以监视KeyboardFocusManager等上的"permanentFocusOwner"属性更改...

Specially, starting from line 974, a listener is created to monitor "permanentFocusOwner" property change on the KeyboardFocusManager etc...

这篇关于Java Swing:如何在TreeListeners:valueChanged之前调用stopCellEditing()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆