I tried doing JTree jt = new JTree(root); and running it and it says
"The constructor JTree(DefaultMutableTreeNode) is undefined".
Here's the screenshot of my code -
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
public class Test {
public static void main(String[] args) {
new Test();
}
public Test() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("hmtl");
DefaultMutableTreeNode n1 = new DefaultMutableTreeNode("head");
DefaultMutableTreeNode n2 = new DefaultMutableTreeNode("body");
root.add(n1);
root.add(n2);
DefaultMutableTreeNode meta = new DefaultMutableTreeNode("meta");
DefaultMutableTreeNode title = new DefaultMutableTreeNode("title");
n1.add(meta);
n1.add(title);
DefaultMutableTreeNode ul = new DefaultMutableTreeNode("ul");
DefaultMutableTreeNode hl = new DefaultMutableTreeNode("hl");
DefaultMutableTreeNode h2 = new DefaultMutableTreeNode("h2");
n2.add(ul);
n2.add(hl);
n2.add(h2);
DefaultMutableTreeNode li = new DefaultMutableTreeNode("li");
DefaultMutableTreeNode li2 = new DefaultMutableTreeNode("li");
ul.add(li);
ul.add(li2);
DefaultMutableTreeNode a = new DefaultMutableTreeNode("a");
h2.add(a);
JTree jt = new JTree(root);
JFrame frame = new JFrame();
frame.add(new JScrollPane(jt));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}