Double-click a JTree node and get its name

后端 未结 4 514
忘掉有多难
忘掉有多难 2020-12-11 16:39

How do I double-click a JTree node and get its name?

If I call evt.getSource() it seems that the object returned is a JTree. I can\'t cast it to a Defa

4条回答
  •  温柔的废话
    2020-12-11 17:10

    MadProgrammer has pretty much everything covered. To get the object you can call

    DefaultMutableTreeNode selectedNode =
       ((DefaultMutableTreeNode)selPath.getLastPathComponent()).
       getUserObject();
    

提交回复
热议问题