I have built my own K-ary tree, which contains nodes storing data about a file system entries. I would like to be able to display this in a JScrollPane
or something similar. I've now found the JTree
class, but am struggling to find how to efficiently translate the information from my tree to the JTree
, while still maintaining my tree functionality, for example I'd like to be able to select a node from the JTree
and get the information from my own tree.
public class DirectoryTree implements Serializable {
private TreeNode Root;
private int numNodes;
private TreeNode Focus;
private LocalDateTime date;
private long totalSizeOnDisk;
I had originally decided to create a class NodeWithButton
, and create a tree hierarchy on a scroll pane using buttons, but I would have to recursively create them and their listeners and it all became a little too much to deal with.