How to construct a tree with 2 or other trees

Hi,
I want to create one tree with 2 trees like :
- first tree :
a
b--c
- second tree :
a
b
d
e
f--i--j
- the result is :
a
b--c
d
e
f--i--j
The first and second tree have the same frame (root). I create one tree when I select one node or one leaf on a tree and put in on a table.
Now with this trees I want to create one tree (fuse trees in the table).
If anyone have a solution.
Thanks.

See this example of merge.
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.text.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class Demo {
private JFrame frame;
JScrollPane scroll1;
JScrollPane scroll2;
JTree tree1;
JTree tree2;
public Demo() throws Exception {
frame=new JFrame();
frame.getContentPane().setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p=new JPanel(new GridLayout(1,2));
DefaultMutableTreeNode node,node1;
DefaultMutableTreeNode root1=new DefaultMutableTreeNode("root");
node=new DefaultMutableTreeNode("1");
root1.add(node);
node1=new DefaultMutableTreeNode("11");
node.add(node1);
node1=new DefaultMutableTreeNode("12");
node.add(node1);
node=new DefaultMutableTreeNode("2");
node1=new DefaultMutableTreeNode("21");
node.add(node1);
root1.add(node);
DefaultTreeModel m=new DefaultTreeModel(root1);
tree1=new JTree(m);
scroll1=new JScrollPane(tree1);
p.add(scroll1);
DefaultMutableTreeNode root2=new DefaultMutableTreeNode("root");
node=new DefaultMutableTreeNode("1");
root2.add(node);
node1=new DefaultMutableTreeNode("11");
node.add(node1);
node1=new DefaultMutableTreeNode("13");
node.add(node1);
node=new DefaultMutableTreeNode("3");
node1=new DefaultMutableTreeNode("31");
node.add(node1);
root2.add(node);
m=new DefaultTreeModel(root2);
tree2=new JTree(m);
scroll2=new JScrollPane(tree2);
p.add(scroll2);
frame.getContentPane().add(p,BorderLayout.CENTER);
JButton b=new JButton("merge");
ActionListener lst=new ActionListener() {
public void actionPerformed (ActionEvent e) {
merge(tree1,tree2);
((DefaultTreeModel)tree1.getModel()).reload();
((DefaultTreeModel)tree2.getModel()).reload();
b.addActionListener(lst);
frame.getContentPane().add(b,BorderLayout.SOUTH);
frame.pack();
frame.show();
public void merge(JTree firstTree,JTree secondTree) {
DefaultMutableTreeNode root1=(DefaultMutableTreeNode)((DefaultTreeModel)firstTree.getModel()).getRoot();
DefaultMutableTreeNode root2=(DefaultMutableTreeNode)((DefaultTreeModel)secondTree.getModel()).getRoot();
mergeNodes(root2,root1);
private void mergeNodes(DefaultMutableTreeNode source
,DefaultMutableTreeNode dest) {
int cnt=source.getChildCount();
for (int i=0; i<cnt; i++) {
DefaultMutableTreeNode child=(DefaultMutableTreeNode)source.getChildAt(i);
int ind=isContained(dest,child);
if (ind==-1) {
dest.add(child);
else {
mergeNodes(child,(DefaultMutableTreeNode)dest.getChildAt(ind));
private int isContained(DefaultMutableTreeNode parent, DefaultMutableTreeNode child) {
int result=-1;
int cnt=parent.getChildCount();
for (int i=0; i<cnt; i++) {
if (((DefaultMutableTreeNode)parent.getChildAt(i)).getUserObject().equals(child.getUserObject())) {
return i;
return result;
public static void main(String[] argv)
throws Exception
Demo html = new Demo();
regards
Stas

Similar Messages

  • How to use PDF files with links to other PDF Files

    How to use a PDF file with links to other PDF files that have been transferred to the same folder

    Are you using a mouse, or a trackpad on a laptop? Either way, your cursor is usually an arrow, right? And presumably it's working/moving MOST of the time, otherwise you wouldn't be able to do anything?
    For example, can you move the cursor arrow to the "Annotate" tool to click on it and go into Annotate mode? If so, can you click on the text tool? If so, does the cursor change to a crosshairs? At what point can you NOT move the cursor around the screen?
    Matt

  • HOW TO CONSTRUCT THE URL WITH INTRADOCUMENT LINKS (#...)?

    I have a url and i want to access or construct the full URL in jsp without losing the # links in the url. If I make a call to the URL lets say using the below mentioned way. when I issue the request.get... Methods to construct the URL inside the JSP page the #doclink were lost. The issue I have is people who have bookmarked a page like this should be automatically taken to that part of the document where the intra document link is define (or book mark link) using anchor tag.
    Is there any method or technique available to get the full url including the #doclink
    http://www.blahblah.com/blah.jsp?pg=/path/otherpath/blah.html#doclink
    is there a way to do it.
    You help in this regard will be greatly appreciated
    Thanks.

    Hey thanks for your reply, I want how can I retain the #doclink in a JSP page without losing it when someone types something like the below mentioned in the browser address bar. If they have bookmarked it this way, this is the way the browser is going to make the request.
    http://www.blahblah.com/blah.jsp?pg=/path/otherpath/blah.html#doclink
    So, inside the JSP page, getRequestURL, getRequestURI, and getQueryString, helps me reconstruct the URL but the #doclink gets missed. I can use the URLEncoding when it's inside the HREF or something, but when called from a browser the above way, I cant do anything really.
    Your help is greatly appreciated.
    Thanks a lot.

  • How to pad a string with space or other character

    length 14 string '00000000000155' turn to length 25 string '00000000000155         ' ,use space to pad string trail.
    using following function:
    CONCATENATE '00000000000155' '         ' into lv_string
    but result is the lv_string ='00000000000155',the spaces were not added the string trail.
    how to achieve this purpose padding string.
    pls help me.
    thank you.

    Hi ,
    Not sure what exactly you require, But in my understanding you need to add one more spave after the doknr no. Please refer this code which could be more useful.
    data: lv_objkt like aeoi-OBJKT,
          lv_doknr like draw-doknr,
          lv_dokar like draw-dokar,
          lv_doktl like draw-doktl,
          lv_dokvr like draw-dokvr,
          lv_slen type i.
    lv_dokar = 'DRW'.
    lv_doknr = '00000000000155'.
    lv_doktl = '000'.
    lv_dokvr = '-'.
    CONCATENATE lv_dokar lv_doknr INTO lv_objkt.
    lv_slen = STRLEN( lv_objkt ).
    lv_slen = lv_slen + 1.
    lv_objkt+lv_slen(3) = lv_doktl.
    CONCATENATE lv_objkt lv_dokvr INTO lv_objkt.
    WRITE: lv_objkt.

  • How to park an invoice with a vendor other than the PO vendor ?

    Dear all,
    Can anybody pl give an idea about how i can park an invoice for a vendor which is different from the PO vendor ?
    regds
    amitava

    hi
    go to MIR7
    here give all detials then in details tab change the po vendor to any other and save

  • How to connect to database with a schema other than current user?

    Dear all,
    I would like to know whether it is possible to specify a specific schema while connecting to a database directly by SQL*Plus command. Usually here is what I do (assuming that db01.WORLD is already in tnsnames.ora)
    $ sqlplus scott/[email protected], in this case the user is SCOTT and the current schema is also SCOTT. If I want to change the current schema I have to use an ALTER SESSION SET CURRENT_SCHEMA command. So what I would like to know is that whether there is an alternative, that is, proceeding in a way where the user SCOTT connects directly (by using SQL*Plus shell) to a SCHEMA other than SCOTT (in other words, is it possible to specify the desired schema at the connection time, for example user SCOTT who connects under a schema named 'management')
    Thanks in advance,
    Dariyoosh

    The ordinary way to do this is to
    1 - grant object privileges from the other schema to scott (Refer to the GRANT command in the online documentation)
    2 - create a private synonym in the Scott user (Look up CREATE SYNONYM in the documentation)
    The only other solution would be to make sure to create an after login trigger running the alter session command.
    Finally two words of advise
    1 You are recommended to leave the user Scott alone, and not mess it up with your own additions.
    2 You seem to treat this forum as a free Oracle class. As the people responding here are volunteers you are kindly advised to stop doing that and use the online documentation at http://tahiti.oracle.com and read at least the 'Getting Started' document and/or the '2-Day' document for your unknown version of Oracle.
    Sybrand Bakker
    Senior Oracle DBA

  • How do you sync contacts with gmail, not other place on computer? I don't know where the contacts came from on that are now on my new phone. There are way too many and it is not my list of contacts I have on gmail. Where else is this from?

    I don't know where the contacts came from on that are now on my new phone. There are way too many and it is not my list of contacts I have on gmail. Where else is this from? I spent a LONG time on gmail going through my list of contacts. There were about 400 and I got it down to about 90. When I went to sync my new phone, ALL 400 synced.
    Thank you for any help!

    Sorry for the repeat...new here. OBVIOUSLY.

  • I need to add funds to a friends account how do i do this with out any other info besides there cell number

    i have a friend down on there luck i would like to add funds to there account  there phone ran out yestarday

        ArthurCarriere2015
    I'd love to help you add the funds needed on your friend's account! That's such a sweet gesture. Are you looking to add funds to a PrePaid account or help pay a PostPaid account? If PrePaid, you can reach out to the PrePay team directly at 888-294-6804. If for a PostPaid account, you can dial 800-922-0204!
    RuthW_VZW
    Follow us on twitter @VZWSupport

  • Constructing Binary tree

    So this is my first post here and i am beginning to like this forum.
    Can anybody help me on how to construct Binary tree from inorder and postorder traversals,i just want to know the algorithm so that i can apply it.
    Please help.

    I would like to pick a minor little nit with this analysis. The algorithm that has been proposed assumes that all the nodes are all distinct and that having selected the root from the end of the post-order listing that it is POSSIBLE to find it in the in-order list. What if you find multiple copies of this node?
    If multiple copies of the root are found, you must have a method to distinguish, which one is the proper dividing point. In the worst possible case, the problem can not be solved at all. For example suppose my post-order and my in-order lists were these:
    a a a a a
    a a a a a
    The shape of the tree is indeterminant in this case.
    If you allow different tree nodes to contain identical values your recursive algorithm needs some modification.
    The fix is this:
    1) allow your recursive algorithm to fail (and report back any success or failure)
    This can and happen if the two lists that you passed in are incompatible. For example they could have different nodes in them.
    2) when you pick the root off the end of the post order list, you search for it in the in-order list, you could find multiple matches or you could find no matches. You must explore each of these independently because each one could lead to a possible different solution, or could lead to no solution. Of course in the case of no matches, you must report back a failure.
    Depending on your needs, you can either stop the first time that you have successfully assembled a tree that matches the two supplied inputs, or you can have it grind on and have it enumerate all the possible tree arrangements that could have generated from the two traversals that you started with.
    It might help to visualize if you write out all the possible trees with just the three nodes AAB. There are 15 of them, 5 with B at the root, 5 with A at the root and B in the left and 5 with B in the right. It is easy to draw the trees and to immediately write both their in-order and their post-order traversals.
    Any traversal is just a list of the 3 nodes and there are 3 arrangements, AAB, ABA, and BAA. There are exactly 9 ordered pairs of these traversals so you can't get all 15 trees from the 9 pairs.
    Sho nuff, three ordered pairs are unambiguous and generate a single unique tree(e.g. in:BAA post:ABA) and six of them come from ambiguous pairs of trees (e.g. in:ABA post:ABA - you can't tell if this is a tree ABA all leaning to the left or all leaning to the right)
    Enjoy

  • How to constuct a table with each row having a button to select

    Hi,
    Imagine i have 5 orders and i want to select one order to view or update in other page.
    How i construct a table with each row having a button to select it.
    I'm having a hard time to do this. How i select a backingBean method in Javascript?.
    Thanks

    I'm trying to put a <h:commandButton> inside <h:dataTable> like this:
                    <h:dataTable id="books" value="#{BuscarLibros.booksSearched}" var="book">
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{messages.title}"/>
                            </f:facet>
                        </h:column>
                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="#{messages.isbn}"/>
                            </f:facet>
                            <h:outputText value="#{book.isdn}"/>
                        </h:column>
                        <h:column>
                            <h:outputFormat value="#{book.fechaPublicacion}">
                                <f:convertDateTime pattern="ddd/MM/yyyy"/>
                            </h:outputFormat>
                            <h:commandButton action="#{BuscarLibros.prepareUpdateBook}" value="Hello WORLD"/>
                        </h:column>
                    </h:dataTable>but it does not call the method.
    If it is outside it calls but inside not. Its strange because Duke's bookstore example from Sun Java EE is like that.
    Any clues?

  • How Do I Use iTunes with Multiple iPods?

    How do I use iTunes and keep 2 iPods music libraries separate? When I plug in my iPod (2nd one), it brings up the music from the 1st iPod registered.
    Thanks

    There are a few different ways to use two iPods with one computer, have a look at this help page for suggestions: How to use multiple iPods with one computer

  • How can an ADF Tree be configured to work with varying levels of heirarchy?

    We have a need for a Locations tree that represents the Locations heirarchy for any one of our clients. Depending on the client the number of levels in a location heirarchy could range from 1 to 9.
    I have created 9 different tree bindings and I can change the tree binding in the jsp page - the example below is for a client with 4 location levels.
    <af:tree value="#{bindings.ScdLocs4View1.treeModel}" var="node"
    binding="#{backing_locations.tree2}" id="tree2">
    For a client with 5 location levels, I'd like to programatically change the value to
    #{bindings.ScdLocs5View1.treeModel.  How can I do this?
    I was thinking I could use the setValue method on the tree control in my page's backing bean.  But I have been unable to get a reference to the tree binding.
    I don't see an appropriate method for finding a Tree Binding.  There are methods for finding an Iterator Binding, an Executable Binding, or a Region Binding (whatever that is).  But how do I "find" a reference to a Tree Binding?
    I have also given consideration to using a single Tree Binding with 9 levels (or rules in the Tree Binding Editor) and finding a way to  programatically "start" the rendering at a particular level (or rule) - in effect telling the ADF Tree control to ignore some number of rules and begin with the specified rule.  But I haven't been able to figure out how to do this either.
    Help would be greatly appreciated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Bill,
    A tree binding is a particular kind of control binding, so you can find it as a control binding and then cast it to the more specific interface to work with it.

  • How to create dynamic tree based on BAPI

    Hi
    I am able to create dynamic tree based on flat file structure example given in SDN . But how to create the tree from BAPI directly.Also when I will be clicking on any leaf node of the tree some data related to the node will be passed to another view.
    Regards
    Ananda

    What i'm trying to do is create an organizational structure.
    Global>Region>Plant-->Corporation
    The output from the RFC is a structure containing every possible combination for orgazational hierarchy. Basically a flat table with record for every possible combinaton of Region-Plant-Corporation. This data needs to be bound to a tree structure so that we can call BW queries based on that level. For example: Give me aged inventory for the SAP corporation within the plant Berlin that is located in the Europe region.
    Now that you understand the business reason will the nodes that represent Region and Plant and corporation be non-singleton nodes or recursive? I was thinking a hierarchy of non-singleton nodes.
    I can bind these nodes to the Region - Plant - Corporation elements returned from in the flat table structure. I will probably get duplicates as a specific Region will be listed multiple times for every possible combination of the data beneath it. I'm not so concerned about that right now as I want to make sure I understand how in Web Dynpro to bind the data to the tree.
    Hopefully this makes some sense. Can you elaborate on how this may be constructed in context of the view?
    Would i create a model node for region (0..n), model node for plant (0..n), and a model node for Corporation (0..n)?
    Or does this sound totally incorrect?
    julian
    We have 3 regions over 50 plants and probably around 500 corporations.

  • How to construct a shortcut to a topic for distribution?

    RH10, WebHelp Pro
    I  find  that if I "copy shortcut" of a topic in the browser (IE), the resulting shortcut looks like this:
    http://server.server/context/directory/server/general/projects/Myproject/Myproject.htm#top icname.htm
    When I then use this URL on our intranet, it does find the correct topic, however the Window is not correct. Specifically, it is using the correct skin but it displays buttons in the toolbar that are NOT selected in the window properties. For example, I do not have "Glossary" selected, but it gives me the glassary button anyway.
    However if the help system is opened via the standard URL which opens the first topic, the window is properly configured, and I assume this is because the string that opens the help system includes the name of the Window.
    Is there a way to insert the Window name in a copied topic shortcut so that if a user enters a topic directly (without opening the helpfile using the standard URL) they will see the correctly confugured toolbar?
    Thank you.

    Willam, thank you.
    Is this method available if I am not using application-based CSH?
    We publish via WebHelp Pro but there is no associated application CSH. The users access the WebHelp content directly through the browser (IE) rather than through a program interface.
    Most users, most of the time, will access the WebHelp by opening the default landing page and then use hyperlinks or the TOC from there to locate a particular topic page. However, as an alternative we  often want to provide a direct link to a page that may be 2, or three levels down the tree.
    If we give them just the URL for that page, they get the page without the navigation pane. Our preference is that the navigation pane (and the Search buttons, etc.)  always open  together with the page.
    In the RH9 documentation I have not found any guidance on how to construct a URL that activates the frameset except by going in via the default start page.
    Mike

  • How to start a application with a login window?

    hi there
    does anyone have any idea on how to start an application with a login window? a login window is the first frame or window to be displayed when an application starts running. and only correct login id and password have been entered the real application will start. any sample out there? thank you.

    You can start a new thread by making a thread object and passing it an implementation of a runnable object. Runnable has just one method, public void run(), this is was gets executed in a second thread. perhaps the code you would use would look something like this.
    <code>
    // set up thread for login window
    new Thread(new Runnable() {
    public void run() {
    // construct your login window here
    // when you are done processing the
    // password....
    if(goodPassword) {
    authorized = true; // a global variable
    notifyAll(); // don't forget this
    else {
    System.exit(42);
    }).start();
    // control does not stop this code gets executed while
    // the above thread is running.
    // Set up main program here. This is done in the
    // backround.
    while(!authorized) {
    synchronized(this)
    { wait(50); }
    // now when the user logs in this frame pops
    // up real quick.
    myFrame.setVisible(true);
    </code>
    Hope you can figure it out.. good luck :)

Maybe you are looking for

  • Error message: The scn engine received a request fro an I/O driver which is not currently installed on the controller.

    Hi, I am currently working in a new application with a cRIO system and I am having some issues when try to run a VI. My actuall configured hardware is as follow: -cRIO-9113 4 slot chassis In this chassis I have installed 3 NI 9514 servo interface mod

  • Import parameter is empty after an RFC call from BW to JCo

    I am calling a Java function (implemented using JCO and deployed on J2EE stack of the Portal box) from within a user-exit in BW (on a separate box) using RFC. The code in BW looks like: CALL FUNCTION 'Z_BW_VALIDATE_PROXY' DESTINATION 'ACF2PROXY'    

  • Framemaker to RTF conversion script

    Hello, I have an requirement for a script to do FM to RTF conversion scripts? Can someone provide any references or samples for this. Thanks & Regards, Shail

  • Pricing Type

    Hi Everyone, I had one query. What is the difference in assigning the PRICING TYPE in T. Code - V/08 (specifically for Pricing Procedures) and in Copy Ctrl for Delivery to Billing (VTFL). I know about Pricing Type for the VTFL part. I am not clear fo

  • Embed font; URL?

    hi all-- I've been trying to simply embed a single font in my .swf web page-- not with actionscript, just as a library symbol, using cs4-- the directions I've seen are pretty straightforward, but for some reason it's not displaying correctly on compu