How to add a TreeNode using a path?

When I doing my project, I get stuck on a portion of my GUI Coding.
My code provide a path such as
/Home/fsloke
/Home/fsloke/directory1
/Home/WorkHard
/Home/WorkSmart
/Home/WorkSmart/Dreamincode
Currently my tree constructed as below:
Home
+ fsloke
---+directory1
+ WorkHard
+ WorkSmart
---+ Dreamincode
May I know how can I add a childNode called "TryHard" under WorkHard?
Generally the path give is "/Home/WorkHard/TryHard".
Don't worried I will split it to
TreeNode Head ="Home"
parentPath ="/Home/WorkHard";
childNode name = "TryHard";
Any clue?
I search in net. All give me the solution when the user click on the tree Node. Then the code use , getSelectedPath() function.
In my case my user not click on the Tree...
Any advise and direction...
Thanx...
I like the DynamicTreeDemo coding from this website http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

you can use this method:
addChildTo("WorkHard","TryHard");
public void addChildTo(String parentObject, String child){
         TreePath parentPath = getTreePath(parentObject);
         if(parentPath != null){
             DefaultMutableTreeNode parent = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
             treeModel.insertNodeInto(new DefaultMutableTreeNode(child), parent, parent.getChildCount());
private TreePath getTreePath(String userObject) {
         java.util.Enumeration nodes = ( (DefaultMutableTreeNode) treeModel.getRoot()).
         preorderEnumeration();
         while (nodes.hasMoreElements()) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
              if (node.getUserObject().equals(userObject)){
                   return new TreePath(node.getPath());
         return null;
}if you are using new DefaultMutableTreeNode("WorkHard"); , then the object name(WorkHard) should be unique , otherwise create node with your own object. Or alter the method what ever you need..
edit:
creation of jtree like
DefaultMutableTreeNode top =
            new DefaultMutableTreeNode("The Java Series");
        createNodes(top);
        treeModel = new DefaultTreeModel(top);
        tree = new JTree(treeModel);
        tree.getSelectionModel().setSelectionMode
                (TreeSelectionModel.SINGLE_TREE_SELECTION);ref:http://java.sun.com/docs/books/tutorial/uiswing/examples/components/TreeDemoProject/src/components/TreeDemo.java
Edited by: david_david on Mar 19, 2008 10:15 AM

Similar Messages

  • How to add external library in class path folder for use in Java call-out?

    Hi,
    I am working with Java callout component in OSB 12c using Jdeveloper.
    Thing is Jar what i am using to perform conversion of json to xml that using external libraries.
    When i have give reference of my project jar to java callout it doen't found external libraries.
    Could you please tell me how to add external libraries in class path folder or How to use to add it through web-logic server ?
    Thanks,
    Pavan

    Hi,
    Thanks, I have solved issue.
    We can add on following path in windows pc:
    C:\Users\your_usename\AppData\Roaming\JDeveloper\system12.1.3.0.41.140521.1008\DefaultDomain\lib
    One you add your external lib here then do restart weblogic server instance.
    Now, you have that external lib or jar in use.
    Cool!

  • How to add classification view using BAPI_MATERIAL_SAVEDATA

    Hi,
    Please any one let me know how to add classification view using BAPI_MATERIAL_SAVEDATA to the material master.
    Thanks,
    shekar

    We use this bapi on a regular basis as well as classification of materials.  We have success doing this in 2 steps.  First step is to save the material using BAPI_MATERIAL_SAVEDATA, second step is to save classification using BAPI_OBJCL_CHANGE  (this can be used for both create and change)  Also look at Function Group CLBPA .   there are several bapi's in that group dealing with object classification, including the one I mentioned..

  • How to add ALV button using OO in module pool program using ALV grid

    Hello Gurus!!!
                  Want some tips related how to add button using ALV Grid(OO).
    I want to display the button for search, sort ....
                 Please suggest the step -by-step procedure for implementation of these button.
                 I am designing the code for transaction FB03. Header data has been displayed but want to display the line items.
                 Kindly suggest your answers.
    Thanks,
    Sachin

    Hi,
    CLASS SELSCR_APPLICATION DEFINITION DEFERRED.
    CLASS SELSCR_APPLICATION DEFINITION.
      PUBLIC SECTION.
       METHODS:
            HANDLE_TOOLBAR
            FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
                IMPORTING E_OBJECT  E_INTERACTIVE,
            HANDLE_USER_COMMAND
            FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
                IMPORTING E_UCOMM.
    ENDCLASS.        "SELSCR_APPLICATION DEFINITION
    CLASS SELSCR_APPLICATION IMPLEMENTATION.
      METHOD HANDLE_TOOLBAR.
        DATA: LS_TOOLBAR  TYPE STB_BUTTON.
    append SAVE icon
        CLEAR LS_TOOLBAR.
        MOVE 'SAVE' TO LS_TOOLBAR-FUNCTION.
        MOVE ICON_SYSTEM_SAVE TO LS_TOOLBAR-ICON.
        MOVE 'Save' TO LS_TOOLBAR-QUICKINFO.
        MOVE ' '  TO LS_TOOLBAR-DISABLED.
        APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
        CLEAR LS_TOOLBAR.
      ENDMETHOD.                    "handle_toolbar
      METHOD HANDLE_USER_COMMAND.
        CASE E_UCOMM.
          WHEN 'SAVE'.
              PERFORM UPDATE_FIELDS.
        ENDCASE.
      ENDMETHOD.
    ENDCLASS.                 "SELSCR_APPLICATION IMPLEMENTATION
    these lines should be after calling method SET_TABLE_FOR_FIRST_DISPLAY
    SET HANDLER G_APPLICATION1->HANDLE_TOOLBAR FOR GRID1.
            CALL METHOD grid1->set_toolbar_interactive.
    rgds,
    bharat.

  • How to add control buttons using Java thorugh serial port?

    Hi everyone,
    I'm new to this forum.
    I have some questions on Java and serial port.
    I want to write a Java program to control my robot, through serial port. For example, when I click "Forward", the robot will go forward, and so on.
    Now I already have the buttons, so next I would like to ask how to interface the buttons with the serial port.
    I already have all the javax.comm things installed.
    below is the code for my buttons:
    import java.awt.*;
    public class ControlButtons extends java.applet.Applet
         GridLayout myLayout = new GridLayout(3, 3);
         Button button1 = new Button(" ");
         Button buttonForward = new Button("Forward");
         Button button2 = new Button(" ");
         Button buttonLeft = new Button("Left");
         Button buttonStop = new Button("Stop");
         Button buttonRight = new Button("Right");
         Button button3 = new Button(" ");
         Button buttonReverse = new Button("Reverse");
         Button button4 = new Button(" ");
         public void init()
              setLayout(myLayout);
              add(button1);
              button1.setVisible(false);
              add(buttonForward);
              add(button2);
              button2.setVisible(false);
              add(buttonLeft);
              add(buttonStop);
              add(buttonRight);
              add(button3);
              button3.setVisible(false);
              add(buttonReverse);
              add(button4);
              button4.setVisible(false);
    }Now I would like to ask for direction on how to add in the code to make it work with serial port.
    Thanks

    The plan is, I have a robot device connected to the serial port.We don't know anything about that device. We don't know how to control it. We don't know what you have to write to the device to make it do anything. Only you know what.
    For example, when I click "Forward", the robot will go forward, and so on.So what do you have to send to make it do that? and same for the other buttons.
    Next, you need to work out from the javax.comm API how to open the serial port and send data to it. This is a standard exercise in learning a new API. You must be able to do this. Again and again.
    But the program is useless. The button can be clicked, but didn't do anything.Because (a) they have no ActionListeners and (b) there is no code to send anything to the serial port.
    You have to write all that. So you also have to look up ActionListener in the Java API and how to attach it to a button. You can do that. We all do that kind of thing every day.
    So next I would like to ask how to interface the buttons with the serial port.You've been asking nothing else since you started, but you've also only done enough investigation of your own to create the buttons. That's only the start.
    The problem is what method and command should I use to make those buttons actually functioning.See above. You've been told part of it several times. The rest only you can answer, because it's your robot.

  • How to add Services programmatically using BAPI_BUS2002_ACTELEM_CREATE_M

    Hi :
    I need to create a project programmatically using the standard PS BAPI. My problem is that I don't know how to add external activities ( Services ) into my project.  I have all steps, except this one. I think that the BAPI BAPI_BUS2002_ACTELEM_CREATE_M should do it but I cannot find where to put the Service Number, Text and Quantity.
    Thanks a lot in advance.
    Jose J. Quezada.

    The problem remains the same. The BAPI_NETWORK_MAINTAIN does not have the fields to add the Services. It can adds an External Activity. The services are External Activities but where are the fields. I need an example or a more specific response. I know how to add a Material for example, but the Services are quite different.
    Kind Regards,
    Jose.

  • How to add jar file in class path ?

    Hello,
    how can I add jar file in system class path.
    I am using Linux and installed java.
    Now I am creating one java package and working programs.
    I want to add commons-net-2.0.jar jar file into class path.
    how can I add in linux systems.
    Thank you.

    the same way you add anything else to the classpath.

  • How to add many hosts using jython interface to sps host database

    Hi,
    we want to create a huge number of virtual hosts into sps repository with jython interface.
    for exemple our variables are:
    hostname = sps1.internet.com
    ip = 192.168.1.1
    masterserver = masterserver
    hardware = v550
    and the script command looks like:
    app.execRaw ( 'hdb.h.add' , { 'name' : hostname , 'desc' : hardware , 'tID' : 'NM:com.vodafone.osmgt#vodRAvhostHT' , 'pID' : NM:masterserver , 'attr' : 'cliServer=cliServer;RA_HOSTNAME=hostname;RA_PROVISIONING_IP_ADDR=ip;RA_DESCRIPTION=Dynamic Infrastructure container;RA_OWNER=n1sps;RA_OWNER_DIR=/var/crash/home/n1sps;RA_OWNER_CREATE_SSH_CONN=true;RA_UID=2241;RA_GROUP=n1sps;RA_GID=2241;RA_INSTALLER_USER=root;RA_SUID=y;RA_INSTALLBASE=/opt/SUNWn1sps;RA_CTYPE=ssh;RA_CTYPE_PARAM=cprefix=/opt/SUNWn1sps/N1_Service_Provisioning_System/agent;RA_LEAVEFILES=n;RA_INSTALL_JRE=/opt/SUNWn1sps/N1_Service_Provisioning_System/common/jre;RA_PORT=1131;RA_CIPHER_TYPE=1;RA_INSTALLER_WORKDIR=/tmp;RA_PARENT_HOST=masterserver;RA_PARENT_OWNER=n1sps;RA_PARENT_OWNER_DIR=/opt/SUNWn1sps/home/n1sps;RA_PARENT_TYPE=MS;RA_PACKAGE_PATH=/var/tmp/spsra;RA_PACKAGE_NAME=cr_ra_solaris_sparc_5.2.sh;RA_REMOTE_PACKAGE_TMP_DIR=/tmp;RA_REMOTE_PRIV_CMD=/usr/local/bin/sudo;RA_REMOTE_PRIV_USER=admin;RA_REMOTE_PRIV_USER_HOME=/home/admin;RA_SRC_SSH_DIR=/opt/home/.ssh;RA_DST_SSH_DIR=/home/.ssh;RA_SSH_AUTH_KEY_FILE=authorized_keys' } )
    unfortunetly we are getting an error when we try to run the n1 sps hdb.h.add command.
    Are we using this command in the right manner ?
    Thanks in advance.
    Christian

    Dear Tarzanek,
    I am Alexis Susset a coleague of Christian.
    Thank you very much for your reply, we are now able to add hosts directly from a Jython script.
    Unfortunetly, we are now encourting a problem with the hdb.h.add command.
    It dies if our hostname (name) is already present in the database.
    We currently need to import a very high number of node and I would like to know how to simply get two outputs (1. added nodes, 2. non-added nodes ).
    Please let me know if you would like me to post the scripts I have.
    PS: I tried to use a hbd.h.lo command but it dies as well when I search for a host that doesn't exist.
    Many thanks and best regards,
    Alexis

  • How to add leading zero using the toString() function?

    Hi,
    I've looked in the user manual and I can't find any reference to toString() for syntax information.  Isn't there a parameter for me to use to specify the string lenght?  And whether to add leading zeros or not?
    Here's the code I need to add leading zeros:
    playbutt.addEventListener(MouseEvent.CLICK, playSound);
    function playSound(e:Event)
    SoundMixer.stopAll();
    var num:Number = Math.ceil(Math.random()*43);
    bigNum.text = num.toString();
    var path:String = "Track No" + bigNum.text + ".mp3";
    trace(path);
    var s:Sound = new Sound(new URLRequest(path));
    s.play();
    The files I'm trying to open starts at "Track No01".
    Any ideas?
    Ron

    Thank you for the code replacement.
    By the way, instead of having the user click a button to start a random music file (MP3), I'd like to get the music going as soon as one loads a webpage and once the first tune is finished playing jump to another randomly selected music file (MP3).
    I've search via Google for ideas but couldn't find anything that came close to what I need done.
    Any ideas?
    Regards,
    Ronald

  • How to Add two numbers using RFC in WD abap

    Dear Experts,
    I have to add the two numbers using RFC.
    I have created the RFC and by using create -> service call i have include that RFC in my WD abap Program.. After that i don't know how to link the input view and to display the result in another view...
    Please help me..
    Thank you.

    This is the third thread that you have posted on this same question.  This is also your second warning that such activity is not allowed in the SCN forums.  Please return to your original thread if you wish to post a follow up question. 
    Beacause this is a duplicate thread it will be locked.

  • How to add network interface using ioctl ?

    I want to do what ifconfig does, but by using ioctls.
    To get or set network interface address, I found some information in the if_tcp(7P) man page. I would like to know more about how to go about it. Do I have to open socket or the pseudo ethernet driver e.g hme ? What are the parameters ? Do I require to only fill the structure ifreq to set the network interface ?
    Thanks in advance.
    -dev

    Are you trying to add a network volume or folder? I believe you can only add folders. Have you tried: Volumes/Archive, losing the first slash.  I was successful in adding a group folder to the dock by using: Volumes/Groups/Example

  • How to add multiple columns using select statement

    Hi friends
    i have two TABLES
    one table Contain only unique Agent code(23,45,56,88)
    second table contain same Agent Code,orderdate & sum(amount)
    now i want to add columns in table 1 according to date and update the amount in that column
    for example if i select start date 1st july 2014 and end date is 15 july 2014
    then i want result 
    select agentcode,amount as 01july2014,amount as 02nd july2014 up to 15th july
    Please HELP.....

    >> I have two TABLES <<
    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. You failed on this too!  Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. Ignorance is fine, but why do you have bad manners? The rules are posted at the front of the forum! 
    >> one [nameless, unknown] table Contain only unique Agent code(23, 45, 56, 88) <<
    You do not know the difference between a code and an identifier!
    CREATE TABLE Agents
    (agent_id INTEGER NOT NULL PRIMARY KEY); 
    >> second table contain same Agent Code, order_date & SUM(order_amount) <<
    Wrong again! The SUM() is an aggregate function and cannot be in a column. Tables have keys
    CREATE TABLE Orders
    (agent_id INTEGER NOT NULL
       REFERENCES Agents(agent_id),
     order_date DATE NOT NULL,
     order_amt DECIMAL (8,2) NOT NULL,
     PRIMARY KEY (agent_id, order_date));
    >> now I want to add columns in table 1 according to date and update the amount in that column <<
    NO! The running total is a computed column. We do not store them.
    >> for example if I select start date 1st July 2014 [sic: 2014-07 -01] and end date is 15 July 2014 [sic: 2014-07-15] <<
    If you have ever read a book on SQL, you would know the correct display format for dates! It is the only one in the ANSI/ISO Standards. 
    SELECT agent_id, order_date,
           SUM(order_amt) 
           OVER (PARTITION BY agent_id
                    ORDER BY order_date
                  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
           AS order_amt_runtot
      FROM Orders
     WHERE order_date BETWEEN '2014-07-01' AND '2014-07-15'; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to add node value using org.w3c.dom.Document?

    Hi ,
    I'm using org.w3c.dom.Document to deal with xml files. I could successfully add nodes , and their attributes. However I could not add a value of the node. (e.g. <myNode>I couldn't add this value</myNode>)
    does anyone know how to deal with this?
    I tried subNode.setNodeValue("the value i can't add"); whereas the subNode is an instance of org.w3c.dom.Node... i know this is interface i of course used the concrete class
    org.apache.crimson.tree.ElementNode
    but when I used the subNode.getNodeValue() i simply got null?
    can u plz help me?
    thanks in advance

    Reading the API documentation for the Node interface might help. At least you wouldn't be surprised when the results are exactly what the documentation says they will be.
    What would really help would be forgetting the idea that an Element can have a value. Text nodes have values, though, so create a Text node and make it the child of the Element node.

  • HOw to add list box using enhacement of standard infotype

    Hi,
    Using enahancement infotype, I wanted to add a list box field in inftyp 01.
    The module pool ZP000100 & screen no 200 already existed .In the layout editor the field didnot get displayed hence I took it from dictionary.
    I have adde the code in pbo & pai for adding values in list box.
    problem is that data is not getting saved when i enter data in pa30 inftyp 01.
    Kindly guide me.
    Regards,
    Rachel

    *

  • How to add expression property using OMB+

    Hi,
    Is it possible to set the expression property for a attribute in the CONSTANT operator through OMB+ ?
    The following commend does not work
    OMBCREATE MAPPING map_name \
    SET PROPERTIES (BUSINESS_NAME, DESCRIPTION) \
    VALUES ('map name ', 'Mapping to test constant') \
    ADD CONSTANT OPERATOR 'CONST1'\
    ADD ATTRIBUTE 'NULL_DATE' OF GROUP 'OUTGRP1' OF OPERATOR 'CONST1' \
    SET PROPERTIES (EXPRESSION) VALUES ('NULL')
    Can anybody provide an example.
    Thanks,
    Sekar,K

    Thanks mark,
    I am not sure what i did wrong yesterday , today the statement is working ? I am using version 9.2.0.4.
    Yesterday initially i tried without operator name ,
    OMBCREATE MAPPING 'M' \
    ADD CONSTANT OPERATOR \
    ADD ATTRIBUTE 'A' OF GROUP 'OUTGRP1' OF OPERATOR 'CONST'\
    SET PROPERTIES ( EXPRESSION) VALUES ('NULL')
    This statement didn't work, after that i have tried with name i was getting different error.
    I will let you know if i am able to re-create the error..
    Does version 10g supports timestamp datatype ?
    Thanks for your help
    Sekar,K

Maybe you are looking for