Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4503615

Persisting DefaultMutableTreeNode does not retain references to childern.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta3
    • generic
    • generic
    • Verified

      Using the new persistence mechanism in 1.4 doesn't seem to work on DefaultMutableTreeNode. Since it's possible to persist a panel with nested components, I would assume that the same thing should hold true for the relationships between tree nodes. Here's a sample program to demonstrate this:

      ---------------------------------- Cut Here --------------------------------
      import java.beans.*;
      import java.util.*;
      import java.io.*;
      import javax.swing.tree.*;

      public class PersistTree {

          private XMLEncoder encoder;
          private XMLDecoder decoder;
          private DefaultMutableTreeNode root, node, temp;

          public static void main(String[] args) {
              new PersistTree();
          }

          public PersistTree() {
              try {
                  encoder = new XMLEncoder(new BufferedOutputStream
                            (new FileOutputStream("tree.xml")));
              } catch(Exception e) {
                  e.printStackTrace();
              }

              node = new DefaultMutableTreeNode();
              root = node;

              temp = new DefaultMutableTreeNode();
              node.add(temp);

              temp = new DefaultMutableTreeNode();
              node.add(temp);

              node = new DefaultMutableTreeNode();
              temp.add(node);

              System.out.println("Before encoding. Child count: " + root.getChildCount());

              encoder.writeObject(root);
              encoder.close();

              try {
                  decoder = new XMLDecoder(new BufferedInputStream(
                            new FileInputStream("tree.xml")));
              } catch(Exception e) {
                  e.printStackTrace();
              }

              root = (DefaultMutableTreeNode)decoder.readObject();
              System.out.println("After decoding. Child count: " + root.getChildCount());

              System.out.println();
          }
      }

      ---------------------------------- Cut Here --------------------------------

      ###@###.### 2001-09-17
      Swing Test Development

            mdavidsosunw Mark Davidson (Inactive)
            elousunw Edmund Lou (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: