E aí, pessoal do GUJ!
Tudo beleza com vocês?
Vejam só o meu código:
public class Tree extends JDialog {
public Tree() {
JPanel p = new JPanel();
List<DefaultMutableTreeNode> nos = new ArrayList<DefaultMutableTreeNode>();
DefaultMutableTreeNode root, child;
root = new DefaultMutableTreeNode("Primeiro nó");
child = new DefaultMutableTreeNode("Filho 1");
root.add(child);
child = new DefaultMutableTreeNode("Filho 2");
root.add(child);
nos.add(root);
root = new DefaultMutableTreeNode("Segundo nó");
child = new DefaultMutableTreeNode("Filho 1");
root.add(child);
child = new DefaultMutableTreeNode("Filho 2");
root.add(child);
child = new DefaultMutableTreeNode("Filho 3");
root.add(child);
nos.add(root);
JTree tree = new JTree(nos.toArray());
p.add(new JScrollPane(tree));
getContentPane().add(p);
}
public void showDialog() {
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
}
public class Main {
public static void main(String[] args) {
Tree t = new Tree();
t.showDialog();
}
}
Legal... Aparecem os nós primários, mas os filhos não aparecem!
O que há de errado?
Desde já, agradeço a ajuda :D
o/