如何在Jtree中刷新XML [英] How to refresh XML in Jtree
本文介绍了如何在Jtree中刷新XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读此处,但是如果xml文件改变了jtree没有重新加载/刷新
如何创建刷新/重新加载Jtree的函数
我尝试编写代码:
I read here , but if the xml file changes the jtree does not reload /refreshes
how to create a function for refresh / reload Jtree
I try to write code :
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
but i got the error : java.lang.NullPointerException
推荐答案
我在< Action
code> getJPopupForExplorerTree()。您可能希望从 XMLTree
构造函数中重新计算 xmlFile
;我在下面对它进行了硬编码:
I added a new Action
to popup
in getJPopupForExplorerTree()
. You'll probably want to re-factor xmlFile
out of the XMLTree
constructor; I've hard coded it for expedience below:
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);
}
}
});
这篇关于如何在Jtree中刷新XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文