【发布时间】:2015-07-26 08:11:57
【问题描述】:
嘿,我是 JAVA 的新手,我正在做一个项目,此时我被卡住了,我想做的是...我已经制作了一个 JTree,其中列出了一些项目,现在我想获取一个JTree 的选定项,将其存储在 String 对象中并将其传递给另一个类,在那里我可以对其进行进一步的操作... 这是我尝试过的
Demo d; //creating object of the class where i want to pass the value
String s;
tree.addTreeSelectionListener(new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent e)
{
node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
System.out.println("You selected " + node);
s=node.toString();
d.getVal(s); //getVal() is the method in class Demo which will receive
my String object
}
});
当我运行程序时,getVal() 中返回一个空值,而不是 JTree 项的文本,请帮助..
【问题讨论】:
标签: java