加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在Jtree中刷新XML

发布时间:2020-12-16 07:58:35 所属栏目:百科 来源:网络整理
导读:我读了 here,但是如果xml文件发生了变化,jtree就不会重新加载/刷新 如何创建一个刷新/重新加载Jtree的函数 我尝试编写代码: refreshAction = new AbstractAction("Refresh",IconFactory.getIcon("delete",IconFactory.IconSize.SIZE_16X16)) {public void a
我读了 here,但是如果xml文件发生了变化,jtree就不会重新加载/刷新
如何创建一个刷新/重新加载Jtree的函数
我尝试编写代码:
refreshAction = new AbstractAction("Refresh",IconFactory.getIcon("delete",IconFactory.IconSize.SIZE_16X16)) {
public void actionPerformed(ActionEvent e) {
    XMLTree xmlClass = null;
    ((DefaultTreeModel) xmlClass.getModel()).reload(); 
    System.out.println("Refresh");
}};

但我得到了错误:java.lang.NullPointerException

我在getJPopupForExplorerTree()中添加了一个新的Action来弹出.你可能想要从XMLTree构造函数中重新考虑xmlFile;我在下面为了方便而硬编码:
popup.add(new AbstractAction("Reload") {

    public void actionPerformed(ActionEvent e) {
        System.out.println("Reload");
        try {
            root = getRoot("xml.xml");
            setModel(new XMLTreeModel(root));
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
        }
    }
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读