Example usage for javax.swing.tree DefaultTreeModel nodesWereInserted

List of usage examples for javax.swing.tree DefaultTreeModel nodesWereInserted

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeModel nodesWereInserted.

Prototype

public void nodesWereInserted(TreeNode node, int[] childIndices) 

Source Link

Document

Invoke this method after you've inserted some TreeNodes into node.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame(Main.class.getSimpleName());
    DefaultTreeModel model = getTreeModel();
    JTree tree1 = new JTree(model);
    JTree tree2 = new JTree(model);
    frame.add(new JScrollPane(tree1), BorderLayout.WEST);
    frame.add(new JScrollPane(tree2), BorderLayout.EAST);
    frame.pack();/*from  www.j  a  v a  2s.  c o  m*/
    frame.setSize(frame.getWidth() + 50, frame.getHeight() + 140);
    frame.setVisible(true);
    Timer t = new Timer(2000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
            root.add(new DefaultMutableTreeNode("A new node"));
            model.nodesWereInserted(root, new int[] { root.getChildCount() - 1 });
            tree1.expandRow(0);
            tree2.expandRow(0);
            frame.revalidate();
        }
    });
    t.start();
}