swing-触发树单元格编辑事件 [英] swing - Triggering Tree Cell Edit Event

查看:113
本文介绍了swing-触发树单元格编辑事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有可编辑节点的JTree.

我如何以编程方式触发树单元格编辑事件,即调出节点重命名文本框来代替突出显示的节点,就像用户手动突出显示该节点并按F2键一样?

基本上,我想添加一个重命名"菜单项或工具栏按钮,以提示用户树的特定功能,并且我希望它在用户突出显示节点时的功能与F2按键相同.

解决方案

1)(通过Mouse/KeyBoard事件)选择了某个节点,并通过TreeSelectionListener进行了侦听,然后选定的路径具有唯一的ID

2)将Swing Action添加到JMenuItem(在JPopup ???中,不清楚您的问题,如何从/to结到???)

3)创建类,作废,随便触发

SwingUtilities.invokeLater(new Runnable() {  
    public void run() {  
        tree.startEditingAtPath(path);  
    }  
});

4)基于 @Michael Dunn 对我的

1) some node is selected (by Mouse / KeyBoard event) and by listening by TreeSelectionListener, then selected path has unique ID

2) add Swing Action to JMenuItem (in JPopup???, not clear from your question, how to get node from /to ???)

3) create class, void, whatever and to fire

SwingUtilities.invokeLater(new Runnable() {  
    public void run() {  
        tree.startEditingAtPath(path);  
    }  
});

4) based on answer by @Michael Dunn to my question on another forum

这篇关于swing-触发树单元格编辑事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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