How-To Add JTree nodes on Expanding

I'm connecting to a database to retrieve information for my JTree, but when I populate my JTree it takes forever due to the table size I'm extracting from. (Big tree). Is there a way to wait until someone opens a folder to add nodes to it?
Thanks for any help.

Hi, another way you can thing about is to create your own Userobject and if the valueChanged you can populate your userObject in the TreeSelectionListener.
The only thing your UserObject must have a toString method. so you can implement a Method which is populating your Sub-Tree direct in your UserObject by invoking it from the TreeSelectionListener.
With getLastSelectedPathComponent() you can get the point where you have to add your children
if you have allowed children. This should also work without your own UserObjects.
I hope this helps.
Greetings Michael

Similar Messages

  • How to add proxy node in message monitoring RWB

    Hi all,
    in RWB message monitoring , i can see two options in drop down list those are integration engine and adapter engine. i want to add one node for proxy run time also.
    can anybody let me know how to add a node for proxy runtime?
    any document or help will be appreciated
    Thanks
    sandeep sharma

    Hi,
    connect your SAP application system (like ERP, etc.)
    to SLD - the same one as PI uses (you need to have PIRWBUSER on ERP too)
    then start transaction SPROXY and build and interface on it
    start it and check if you see the new node in message monitoring
    Regards,
    Michal Krawczyk

  • How to add a node to already existing hierarchy in BW?

    Hi Gurus,
    Can someone please tell me step by step how to add a node to the hierarchy.
    Thank you,
    Olga

    If I need to add an element to the node, I right click on the node and is it 'insert Characteristic'?
    Sorry I must add one more thing.If it is the first time you add an element to the node then right click the folder(node).But if you already have elements in the node then right click any element and choose add element(country,material whatever).If you choose add a characteristic, then you add another type of element(e.g you have materials in the node and add some countries by choosing add a characteristic)
    When I try to add a node, it gives me a list of nodes I can choose from
    In fact when you right click a folder, there must be an option like "Create nodes".Do you right click on a folder, don't you?You create nodes like that.
    Nevertheless, there is one more way to edit or create a hierarchy.You can load a hierarchy from a flat file.But I am not sure it is worth it.If you have lots of elements and nodes then I propose you to go that way.Step by step document:
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/601b0771-92c4-2d10-a081-f947a516bd20?QuickLink=index&overridelayout=true

  • How to change JTree nodes background?

    hello there
    i have a jtree which i set its background to red
    but the nodes background is still white
    why?and how to set the nodes background to red too?
    and how to remove the tree border
    because i tried setting it to null and it doesn't work?
    here is my code:
    package view;
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.tree.*;
    class TreeComponent{
      public static void main(String[] args) {
        JFrame frame = new JFrame("Creating a JTree Component!");
        DefaultMutableTreeNode parent = new DefaultMutableTreeNode("Color", true);
        DefaultMutableTreeNode black = new DefaultMutableTreeNode("Black");
        DefaultMutableTreeNode blue = new DefaultMutableTreeNode("Blue");
        DefaultMutableTreeNode nBlue = new DefaultMutableTreeNode("Navy Blue");
        DefaultMutableTreeNode dBlue = new DefaultMutableTreeNode("Dark Blue");
        DefaultMutableTreeNode green = new DefaultMutableTreeNode("Green");
        DefaultMutableTreeNode white = new DefaultMutableTreeNode("White");
        parent.add(black);
        parent.add(blue);
        blue.add(nBlue);
        blue.add(dBlue);
        parent.add(green );
        parent.add(white);
        JTree tree = new JTree(parent);
        tree.setBackground(Color.red);
        tree.setBorder(null);
        frame.add(tree);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setUndecorated(true);
        frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
        frame.setSize(200,200);
        frame.setVisible(true);
    }

    how to set the nodes background to red too?
    ((JComponent) tree.getCellRenderer()).setOpaque(true);[/code\
    how to remove the tree borderWhat border?
    db                                                                                                                                                                                                                                                                                                                                       

  • 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 add child node in Tree table programmetically

    Jdev Version 11.1.1.4.0.
    I have created tree table programmetically in bean.
    I have to add child node to tree table component on button click event on page.
    Please let me know how to do this in bean.
    Regards,
    Kiran

    How are you creating the tree pro-grammatically?
    If you are adding a new node to underlying data structure and refresh the tree - the tree will get updated with the new data.
    Thanks,
    Navaneeth

  • 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();

  • How to set Jtree Nodes' name into TextField??

    Dear Sir:
    I have following code to select any file's name then put into TextField,
    see:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.io.File;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.TreePath;
    public class JTreeSplitChooseDemo extends JPanel implements ActionListener{
        JFileChooser fc;
        JButton openButton, saveButton;
        JTextField jtf;
      public JTreeSplitChooseDemo() {
        final JTree tree;
        final JTextField jtf;
        JPanel jp= new JPanel();
        setPreferredSize(new Dimension(500,350));
        jp.setPreferredSize(new Dimension(500,300));
        DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options");
        DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
        top.add(a);
        DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
        a.add(a1);
        DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
        a.add(a2);
        DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
        top.add(b);
        DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
        b.add(b1);
        DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
        b.add(b2);
        DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
        b.add(b3);
        tree = new JTree(top);
        JScrollPane jsp = new JScrollPane(tree);
        jsp.setPreferredSize(new Dimension(500,300));
        tree.setPreferredSize(new Dimension(500,300));
        add(jsp, BorderLayout.CENTER);
        jtf = new JTextField("", 20);
        add(jtf, BorderLayout.SOUTH);
        tree.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent me) {
            TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
            if (tp != null)
              jtf.setText(tp.toString());
            else
              jtf.setText("");
      public JPanel JTreeText() {
             JPanel jp= new JPanel();
             JPanel jpanel= new JPanel();
             setPreferredSize(new Dimension(400,350));
             jp.setPreferredSize(new Dimension(400,300));
             JScrollPane jsp = new JScrollPane(jp);
             jsp.setPreferredSize(new Dimension(400,300));
             jpanel.add(jsp, BorderLayout.CENTER);
             jtf = new JTextField("", 20);
             fc = new JFileChooser();
             openButton = new JButton("Open a File...",new ImageIcon("images/hui.gif"));
             openButton.addActionListener(this);
             JPanel buttonPanel = new JPanel(); //use FlowLayout
             buttonPanel.add(openButton);
             //jp.add(buttonPanel, BorderLayout.PAGE_START);
             jp.add(buttonPanel, BorderLayout.NORTH);
             jp.add(jtf, BorderLayout.CENTER);
             return jpanel;
      public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.getContentPane().add(new JTreeSplitChooseDemo(), new BorderLayout().WEST);
        frame.getContentPane().add(new JTreeSplitChooseDemo().JTreeText(), new BorderLayout().CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 350);
        frame.setVisible(true);
    @Override
    public void actionPerformed(ActionEvent e) {
         //Handle open button action.
        if (e.getSource() == openButton) {
          int returnVal = fc.showOpenDialog(JTreeSplitChooseDemo.this);
          if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
             jtf.setText(file.getName());
          } else {
             jtf.add("Open command cancelled by user.", null);
    }For example, If i choose file : C:\temp\ftp\TestMyFile.txt
    after I press open button, then choose it, then, the file name TestMyFile.txt will be displayed in the textFiled.
    My problem is that I hope to choose any node in the JTree on the left Panel, then when I choose it, this JNode I selected will be displayed its name in the TextField.
    Not file, I need choose JNode,
    ie, B1 under B node, or A1 under A node, then B1 will be displayed in jtf.
    How to do this one??
    Can Guru throw some light??
    Thanks
    sunny

    Thanks, camickr.
    My fault not to explain detail.
    Actually I mean that I will use a dialog box(very much look like a file choose) that is something like a file chooser then I can browse over JTree first for any node then I can choose or select a node in this JTree, after select this node, its name is populated into text field. My one is I will use a JTree browser (something like that) to get a tree node.
    ie, this showOpenDialog will browse over JTree, not File system.
    I did not want to click on the node then this node name is populated into textField.
    the sample (http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html) shows that when I select a node, then its name was populated to a destination.

  • How to highlight JTree node without selecting it

    Hello,
    I want to highlight a Tree Node without selecting it.
    Anybody having ideas as to how i can do it.
    thanks in advance.
    Reg,
    sai

    for what it's worth for anyone with the same problem, the problem was that the node was being regenerated as a different object so each time it went through the object wasn't the same and therefore had a new expanded value as default of false.

  • How to add two nodes in a Hierarchy

    Hi Experts,
                    I have 0ACCOUNT hierarchy using for P&L report. I developed this hierarchy to get the values of Revenue and Expenses (nodes).  Once I get this values I want the difference of this two to get the Income Statement. I have Revenue and Expense in 3 rd level and Income statement node is in 2nd level.
                   My report looks like as follows
                   Month 1        Month 2    Variance    Variance %
    Revenue      1000            1200           XXX           XXX %
    Expense       800              950           XXX           XXX%
    Inc Stmt       200            250             XXX           XXXX    ( How can do this calculation)
                   Please some tell me how to calculate the difference of Revenue and Expense using hierarchy nodes.
    Thanks
    Ganesh Reddy.

    Hi,
             My problem is fixed, they are calcualted if you have a child nodes. How means Revenue is positive and Expenses are negative. So we get difference of this two.
    Thanks
    Ganesh Reddy.

  • SQL Server Distributed Partitioning Views how to add a new node online

    We are using distributed partitioning views in SQL Server 2012 Enterprise Edition for scaling out our data across more than one servers. Now we faced to question how to add a new node (server) into the scale outed db servers system without sending the servers
    down, so our users will be able to use them during the process as well.
    For example we have 4 servers with scaled out data. When we add the new empty server, the CHECKINGs for the partitioning columns should be reorganized. But during the process the partitioning views are not working.
    The High Availability, Always On or Failover Cluster approaches seem are not resolve the problems.
    So my question is how to add new node online?
    KH

    Thank you Erland for the reply.
    Yes, it's sounds as possible solution but has some not resolvable nuance in it. Let's say we copied some data from Node5 to new added Node6. Let's assume in Node5 we had data in Table1 with partitioning column's values 100,101,102,103,104,105,106.  Now
    we want to copy part of the rows with partitioning column's values 103,104,105,106 from Node5.Table1 into Node6.Table1. With this Node5 will contain less data and will work more quickly (less IO, less CPU usage etc), and the rest data will be contained on
    Node6. But because of Node5 is already in use, the Node5.Table1 contains CHECK CONSTRAINT = ParttionColumn should be from 100 up to 106. This is check for Node5. The Distributed Partitioning Views are already using the CHECKs to identify what server should
    be used to get data from.
    Now when we copied part of the Node5.Table1 rows to Node6.Table1 the views are still using the 103-106 rows from Node5.Table1 because the CHECK points there. Then we include the newest Node6.Table1 in the distributed partitioning views. OK, but we should
    set some CHECK on new Node6.Table1 which will be used by views. We can't set intersecting checking like Node5 has CHECK 100-106 and Node6 has CHECK 103-106. We also can't edit Node5 check and set it 100-102 untill the data will be removed in it. But this means
    that the data will not be available during the execution. 
    So, any ideas ?
    KH

  • How to add own customized transaction in SPRO (IMG Menu Path)

    Dear All,
    I have a requirement of adding new customized transaction in IMG menu path. Can you please help me out how to do that?
    Best wishes,
    Atanu

    Hi
    Can you try this way:
    You need to modify the structure ( node ) that you want to modify using transaction SIMGH. First you need to go to transaction SIMGH.
    In the IMG structure just press f4 -> you need to give the title of the structure that needs to be edited. f8. Then you can modify the structure -> insert node.
    You need to give the node text.
    After creating the node, click on the node and select insert activity.
    In the ID field give an entry, Give the description in 'name'.
    Please check this link on how to add a node in IMG.
    http://help.sap.com/saphelp_sm32/helpdata/en/9a/b7b2375ca97f68e10000009b38f8cf/content.htm
    Regards,
    Sreeram

  • Add JTree in JTable

    How to add JTree in JTable?
    Please tell me?

    you need to use a TableCellRenderer, that implements your JTree, for cell renderers see http://java.sun.com/docs/books/tutorial/uiswing/components/table.html and http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#renderer
    thomas

  • Letting a user add a node to a tree

    Hi,
    Currently I have a tree that is built dynamically with a
    remote object call. Also, if the user clicks on a node, a menu pops
    up allowing the user to create a child for the node. How do I let
    the user add a node to the tree ? I saw tangential examples showing
    how to add xml nodes, but I am unable to translate that to trees
    that are populated NOT in static xml, but from a remote object
    call.
    I have the following function signature :
    // parentIndex - the index of the parent node, where the user
    wants to add a child node
    // childLabel - the label for the child node.
    private addChild(parentIndex:int, childLabel:String) {
    Thanks for your help.

    Hi Tracy, this the code I am using from PeterEnt's blog. His
    example was about drag-and-drop. I am trying to use it (maybe I
    shouldn't:) for my child node insertion.
    myTree.selectedIndex = parentIndex;
    var node:XML = myTree.selectedItem as XML; // interestingly,
    myTree.selectedItem is not null, but node is null. Why ?
    var p:*;
    if(myTree.dataDescriptor.hasChildren(node)) {
    p = node;
    parentIndex = 0;
    else { // I am getting a null pointer exception here
    p = node.parent();
    var insert:XML = <node />;
    insert.@label = "New Toy";
    insert.@type = "Toy";
    myTree.dataDescriptor.addChildAt(p, insert, parentIndex+1);
    I am getting the parent value (label etc) correctly for
    myTree.selectedItem. But when I do node:XML = myTree.selectedItem
    as XML, I am getting null value for null. That's why I asked in my
    first message if there is a difference in populating the data
    statically as XML v.s. loading the data using remote object (which
    is the case here).
    Appreciate your help.

  • Add Second Node in DMZ

    Hi,
    We are on EBS 12.1.3 and have single application node accessible over intranet. We want to add another node. I know all the steps to add the node by cloning but have some confusions so would like to clarify.
    While cloning the second node autoconfig will run automatically. This will add the node in FND nodes so now we will have two apps tier in FND nodes.
    1) Do we need to still run adaddnode.pl; if yes then why?. if no then what is the use of adaddnode?
    2) After the autoconfig run 2nd node will become the primary node and application will be accessible only though 2nd node url. 2nd Node URL will be mapped to a virtual host in Load Balancer. and DMZ configuration will be over but which url will be used by the intranet users.
    I want to separate URL basically. If only one url is required then i can use the virutal host names in the context of both nodes and autoconfig will do the rest. But i need two URLs and both should be working.
    Prompt replies will be much appreciated.
    regards,

    Hi;
    Please check below which could be helpful for your issue:
    How to Add Node/Instance or Remove Node/Instance in 10gR2, 11gR1 and 11gR2 Oracle Clusterware and RAC [ID 1332451.1]
    Re: How to add new node in 11gR2 RAC
    Regard
    Helios

Maybe you are looking for