How to Dinamicaly load-save JTree nodes ?

Hi !
A have one program. Use 1 JTree with a lot of nodes. (200.000-1.000.000. is much)
For every node store is sored 7-8 boolan variables, 2long, and 5-6 String variables, whitch legth is 3-20. (Not much).(Information about files avaible somevhere)
Now I save the root node(or the treeModel ) with ObjectOutputStream and load with ObjectinputStream. It generates 10-45Mb. I can export to XML but need about 350Mb memory to construct the DOM.an dthe Savad xml is 90Mb. It take long time to load, take a lot of memory.
But don`t need to be stored all in the sytem memory. It is enugth to be stored one node, and after the user select that node load information about chilld nodes from the stored file and construct the child nodes, if the child node is selected(or try to be expanded) load information from file again.
I think it is an idea to store somehow key-values but with PropertiesResourceBundle it is slow again. How is posible to store my data?
Can you help me to store data dinamicaly in file and read from that?.

How is posible to store my data?This is the real question, isn't it? Not how to load and save them, that comes later.
You give each node an arbitrary identifier. A number works well. Then create a database table where you store the node identifier, the node's parent identifier, and the various information that belongs to the node. (If the node is the root node, store NULL as its parent).
Then, to load the root node, find the database row whose "parent" column is NULL. Read that, make a node out if it, and set it as the root of your tree. To load the children of a node (you'd do this in a TreeWillExpandListener if I remember the name correctly) you find the database rows whose "parent" column is the node that is expanding. Read them, make nodes out of them, and add them as children to that node.
There's more to it than that, of course, but that should be a start, I hope.

Similar Messages

  • How can i change the particular node color in Jtree?

    I have constructed the tree.i dont know how to set the color for the particular node then how can i change the particular node icon depends on some conditions like if we will give the input whether it is available in jtree that node icon only changed.Anyone please help me as soon as possible.

    hi,
    i saw that tutorial.from that book i dont get the particular node cell renderer.i got a cell renderer for tree only.i attached my code in this mail.pls see and help me if u will do
    mport pack.Prop;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Font;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Properties;
    import java.util.Set;
    import java.util.StringTokenizer;
    import java.util.Vector;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.UIManager;
    import javax.swing.text.Position;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.MutableTreeNode;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreePath;
    public class ReadProperty3 extends JFrame{
    String str,key;
    static JTree tree;
    static Vector v;
    StringTokenizer st;
    static DefaultMutableTreeNode root;
    DefaultMutableTreeNode t;     
    public Object[] o;
    public static void main(String[] args) throws IOException {
    ReadProperty3 r = new ReadProperty3();
    Prop p=new Prop();
    JFrame f=new JFrame();
    p.show();
    Object[] o=v.toArray();
    int startRow = 0;
    String prefix =p.s;
    TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Forward);
    //if(prefix.equals(root.getChildAt(0).toString()))
    if(prefix.equals("2000"))
         System.out.println("Node 2000 found");
         else if(prefix.equals("3000"))
              System.out.println("Node 3000 found");
         else if(prefix.equals("4000"))
              System.out.println("Node 4000 found");
         else
              System.out.println("Node not found");
         for(int i=0;i<v.size();i++)
              //((DefaultTreeModel)tree.getModel()).reload();
              DefaultTreeCellRenderer ren=(DefaultTreeCellRenderer)tree.getCellRenderer();
              Icon openIcon = new ImageIcon("C:/apache-tomcat-5.5.12/webapps/jsp-examples/images/execute.gif");
              Icon closedIcon = new ImageIcon("C:/apache-tomcat-5.5.12/webapps/jsp-examples/images/execute.gif");
              Icon leafIcon = new ImageIcon("C:/apache-tomcat-5.5.12/webapps/jsp-examples/images/read.gif");
              if(o[0].equals(p.s))
                   ren.setBackgroundSelectionColor(Color.MAGENTA);
                   ren.setBackgroundNonSelectionColor(Color.YELLOW);
                   //ren.setTextSelectionColor(Color.YELLOW);
                   //ren.setTextNonSelectionColor(Color.BLUE);
                   ren.setClosedIcon(closedIcon);
                   ren.setFont(new Font("Impact",Font.ITALIC,14));
              else if(o[1].equals(p.s))
                   ren.setLeafIcon(leafIcon);
                   ren.setFont(new Font("Impact",Font.ITALIC,10));
                   UIManager.put("Tree.leafIcon", leafIcon);
              else if(o[2].equals(p.s))
                   ren.setOpenIcon(openIcon);
                   ren.setFont(new Font("Dialog",Font.BOLD,9));
    public ReadProperty3(){
         super("JTree With Properties");
         try{
    int c = 0;
    while(c == 0){
    c = 1;
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter file name which has properties extension :");
    str = bf.readLine();
    File f = new File(str + ".properties");
    if(f.exists()){
    Properties pro = new Properties();
    FileInputStream in = new FileInputStream(f);
    pro.load(in);
    System.out.println("Key: " + pro.keySet());
    System.out.print("Enter Key : ");
    key = bf.readLine();
    String p = pro.getProperty(key);
    st = new StringTokenizer(p,"=,");
    root=new DefaultMutableTreeNode(key);
    v=new Vector();
    while(st.hasMoreTokens())
         String val=st.nextToken();
         v.add(val);
         o=v.toArray();
         System.out.println(val);
         t=new DefaultMutableTreeNode(val);
         root.add(t);
         tree=new JTree(root);
         tree.setEditable(true);
         JScrollPane jp=new JScrollPane(tree);
         // tree.setCellRenderer(new CellRenderer());
         Container content=getContentPane();
         content.add(jp,BorderLayout.CENTER);
    setSize(250,275);
    setVisible(true);
    addWindowListener(new ExitListener());
    else{
    c = 0;
    System.out.println("File not found!");
    catch(IOException e){
    System.out.println(e.getMessage());
    }

  • Xml in JTree: how to not collpase JTree node, when renaming XML Node.

    Hi.
    I'm writing some kind of XML editor. I want to view my XML document in JTree and make user able to edit contents of XML. I made my own TreeModel for JTree, which straight accesses XML DOM, produced by Xerces. Using DOM Events, I made good-looking JTree updates without collapsing JTree on inserting or removing XML nodes.
    But there is a problem. I need to produce to user some method of renaming nodes. As I know, there is no way to rename node in w3c DOM. So I create new one with new name and copy all children and attributes to it. But in this way I got a new object of XML Node instead of renamed one. And I need to initiate rebuilding (treeStructureChanged event) of JTree structure. Renamed node collapses. If I use treeNodesChanged event (no rebuilding, just changes string view of JTree node), then when I try to operate with renamed node again, exception will be throwed.
    Is there some way to rename nodes in my program without collpasing JTree?
    I'am new to Java. Maybe there is a method in Xerces DOM implementation to rename nodes without recreating?
    Thanks in advance.

    I assume that "rename" means to change the element name? Anyway your question seems to be "When I add a node to a JTree, how do I make sure it is expanded?" This is completely concerned with Swing, so it might have been better to post it in the Swing forum, but if it were me I would do this:
    1. Copy the XML document into a JTree.
    2. Allow the user to edit the document. Don't attempt to keep an XML document or DOM synchronized with the contents of the JTree.
    3. On request of the user, copy the JTree back to a new XML document.
    This way you can "rename" things to the user's heart's content without having the problem you described.

  • How could i get the selected node in the JTree

    getLastSelectedPathComponent() �returns the parent node of currenr selected, so how could I get the selected node itself in the JTree
    I will appretiate for any help!

    i think you can get by....
    TreePath treePath = tree.getSelectionPath();
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();

  • How to sort Jtree node?

    Now, I want to sort tree node by increasing.
    for example there are three child node:
    [20 -40][
    10 - 20]
    [30- 60].
    they are added to JTree node by different order.but are shown in increasingorder.
    like this:
    [10 - 20]
    [20 -40][
    [30- 60].
    how to control tree node.

    Implement the Comparable interface in t he userobject class and possibly the toString(0 as well.
    Ex.
    public class UserObject implements java.lang.Comparable{
    public int compareTo(Object obj) throws ClassCastException
    public String toString()

  • How to allow multiple selection of nodes in a JTree

    How to allow multiple selection of nodes in a JTree ?
    Thanks
    S.Satish

    By default when you create new instance og JTree the selection model is multiple selection. And if you want to change it you use next:
    tee.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    or
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
    or
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    Hope will help!

  • How to load/save a file in the WEB-INF?

    how can i load and save files in the WEB-INF directory using servlet?

    This doesn't save files. And in order to reuseability and maintainability, I'd rather use java.io and passing the path/filename around in File object.
    You can retrieve the absolute path for "/WEB-INF" byString absoluteWebInfPath = getServletContext().getRealPath("/WEB-INF");Then you can use that to read/write files.
    File file = new File(absoluteWebInfPath, "filename.ext");
    InputStream input = FileUtil.read(file);
    FileUtil.write(file, input);and so on.

  • How to get the icon type of a JTree node, very urgent

    hi,
    i need to get the type of a JTree node but don't know how. this is quite an emergency. please help. thank you all.
    -joey

    there are several icons defined in the DefaultTreeCellRenderer class, such as closedIcon, leafIcon, openIcon. i was wondering if there is any way to get the icon type of a node. thanks for your reply.
    -joey

  • How do I load and save to my iMac a dvd purchased elsewhere?

    how do I load and save to my iMac a dvd purchased elsewhere?  Thank you.

    The mods here are adverse to mentioning software to duplicate commercial media, which is called "ripping." However, you can search outside of this forum for the software you need.

  • How to get the TreePath of a JTree Node

    hello all:
    Given a DefaultMutableTreeNode JTree node, how i can
    get the TreePath for it.
    because I want to use this method to fire the function expandPath(TreePath path)
    thank you very much!
    -Daniel Mark

    thank you I had got idea from forum
    http://forum.java.sun.com/thread.jsp?forum=31&thread=381249
    thx again.
    -Daniel

  • How to post an Event (mouse left click) to JTree node

    Hi,
    I am using JTree for my application just like the windows explorer tree. By default, Jtree node will got focus using left click. But, I'd like that my tree will detect a right click so that I can copy any file to the Jtree. I've added a mouselistener to it but the node is not selected by the right click. Anyboby can teach me how to post a mouse left click event to the Jtree so that it will become selected using left click.
    Thanks a million

    See if this is useful
    public void mouseClicked(MouseEvent event)
    Object object = event.getSource();
    if (object == mTree)
    mTree_mouseClicked(event);
    private void mTree_mouseClicked(MouseEvent event)
    if(event.getModifiers()==event.BUTTON3_MASK)
    //your logic goes here
    }//close method

  • In the JTree model,how can I transfer DefaultMutableTreeNode into Node?

    In the JTree model,how can I transfer DefaultMutableTreeNode into Node?

    hi,
    add it to the jtree.getModel().getRoot().add(node);
    Cheers,
    Gokul

  • How to hide node handles (legs) from JTree nodes?

    Hello,
    Does anyone has an idea on how to not display JTree node handles (legs)?
    Thank you,
    Mindaugas

    You can do it with Java/Metal look and feel by doing this:
    JTree tree = new JTree(...);
    tree.setClientProperty("JTree.lineStyle", "None");
    For any other L&F, you will have to look at the UI code.
    Mitch Goldstein
    Author, Hardcore JFC

  • How to sort jTree Nodes

    Hi,
    I am interested in whats the easiest way to sort jTree Nodes alphabetically. Is there any Method to do this directly or may i use something like quicksort?
    Thanks for help
    Mirco

    Thanks Hamed,
    Well, I work in your code, and I post here.
      public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) {
                     for (int i =0; i<root.getChildCount()-1; i++) {
                              DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
                            String nt = node.getUserObject().toString();
                            for (int j=i+1;j<=root.getChildCount()-1;j++)
                                     DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) root.getChildAt(j);
                                        String np = prevNode.getUserObject().toString();
                                System.out.println(nt+" "+np);
                                if (nt.compareToIgnoreCase(np)>0) {
                                               root.insert(node, j);
                                             root.insert(prevNode, i);
                            if (node.getChildCount() > 0) {
                        node = sortTree(node);
                     return root;
        }and this code I used after include in jtree
      public  void jTreeSortingBegin()
              dn = (DefaultMutableTreeNode)treeModel.getRoot();
              treeModel.reload();
              dn = sortTree(dn);
              treeModel.reload(dn);
        }for exemple
      addObject(jTextField1.getText());
            jTreeSortingBegin();

  • I have hierarchy data in R/3 side how will i load that data from R/3 to BW

    Hi all,
    i have my hierarchy data in the R/3 side how will i load that data from  R/3 to BW side
    Regard
    Kiran Kumar

    Hi Kiran,
    Here is the procedure:
    1.      In the Data Warehousing Workbench under Modeling, select the InfoSource tree.
    2.      Select the InfoSource (with direct update) for the InfoObject, to which you want to load the hierarchy.
    3.      Choose Additional Functions® Create Transfer Rules from the context menu of the hierarchy table object for the InfoObject. The Assign Source System dialog box appears.
    4.      Select the source system from which the hierarchy is to be loaded. The InfoSource maintenance screen appears.
    ○       If the DataSource only supports the transfer method IDoc, then only the transfer structure is displayed (tab page DataSource/Transfer Structure).
    ○       If the DataSource also supports transfer method PSA, you can maintain the transfer rules (tab page Transfer Rules).
    If it is possible and useful, we recommend that you use the transfer method PSA and set the indicator Expand Leaf Values and Node InfoObjects. You can then also load hierarchies with characteristics whose node name has a length >32.
    5.      Save your entries and go back. The InfoSource tree for the Data Warehousing Workbench is displayed.
    6.      Choose Create InfoPackage from the context menu (see Maintaining InfoPackages). The Create InfoPackage dialog box appears.
    7.      Enter the description for the InfoPackage. Select the DataSource (data element Hierarchies) that you require and confirm your entries.
    8.      On the Tab Page: Hierarchy Selection, select the hierarchy that you want to load into your BI system.
    Specify if the hierarchy should be automatically activated after loading or be marked for activation.
    Select an update method (Full Update, Insert Subtree, Update Subtree).
    If you want to load a hierarchy from an external system with BAPI functionality, make BAPI-specific restrictions, if necessary.
    9.      If you want to load a hierarchy from a flat file, maintain the tab page: external data.
    10.      Maintain the tab page: processing.
    11.      Maintain the tab page: updating.
    12.      To schedule the InfoPackage, you have the following options:
    ○       (Manually) in the scheduler, see Scheduling InfoPackages
    ○       (Automatically) using a process chain (see Loading Hierarchies Using a Process Chain)
    When you upload hierarchies, the system carries out a consistency check, making sure that the hierarchy structure is correct. Error messages are logged in the Monitor. You can get technical details about the error and how to correct it in the long text for the respective message.
    For more info visit this help pages on SAP Help:
    http://help.sap.com/saphelp_nw04s/helpdata/en/80/1a6729e07211d2acb80000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/3d/320e3d89195c59e10000000a114084/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/80/1a6729e07211d2acb80000e829fbfe/frameset.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4dae0795-0501-0010-cc96-fe3a9e8959dc
    Cheers,
    Habeeb

Maybe you are looking for

  • FIXED: MacBook Pro + DVI-to-Video Adapter + Windows

    The Apple DVI-to-Video adapter (M9267G/A) never worked properly under Windows XP on a MacBook Pro (NVIDIA 8600M GT). The s-video and composite outputs produced a very distorted image under Windows, while the image was clear under Mac OS X. Boot Camp

  • Control printing from report

    Hi friends ,          i have to control the printing of a report on the condintion that if a field value is changed then printing should not happen. so i want to know how to control this behavior of a report. your hints are highly appreciated. Thanx

  • Urgent : packaging wizard

    I'm using Oracle 8.1.7 & Oracle9i Lite I've published a Visual C++ application with the packaging wizard importing the right tables, sequences & primary keys. But once my client is synchronized the sequences don't exist anymore in the .odb database.

  • Changing permissions for makepkg files

    I'm made an exaile 0.2.9 package for x86_64 for myself since it's not in the x86_64 repositories yet.  I was thinking of fixing it up and poping it in the AUR.  I'm having a bit of trouble with it though. When it installs, the executable looses the e

  • Problem printer

    Problem : printer hp laserjet 400  mfp m425 dn print "GET/ HTTP/1.0 " is first page. Thank you for answer