JTree questions (1) Re-populating (2) Adding popups

Hi all,
I've just started to use a JTree in my application and I've encountered two
problems. Sorry if these have been covered before - I've been Googling around
for answers.
I have a UI panel ...
http://photos1.blogger.com/blogger/541/411/1600/TreeDemo.gif
... where a tree is populated with stock quotes from different
sources. The user selects the stock and the tree should update to show the
quotes for that stock. The quotes are read from a DB and I want the user to
be able to delete from the DB using a pop-up on the leaf nodes.
Problems
(1) Re-populating
The only way I've got this to work at this time is to create a new tree from scratch,
based on the stock name, then put it into a new scroll panel, remove the old scroll
panel from the container and add the new one. Not good is it? Nasty, nasty.
I've read a lot about needing to interact with the tree model - is that right?
(2) Adding popups
I want to be able to delete items from the DB by doing a right-click on the leaf
nodes and selecting "Delete" from the pop-up.
I find that I can't add a mouse listener to the DefaultMutableTreeNode used to
hold the leaf item. Should I subclass DefaultMutableTreeNode and implement some
interface to do this?
Any insights very much appreaciated.

I know I'm asnwering my own question here - but I found the answer to teh re-population question while waiting.
I now use the DynamicTree class that is included in the Sun tutorial here
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
Specifically, here
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html#DynamicTreeDemo
I'd still welcome any suggestions on the pop-up menu question!

Similar Messages

  • Confused -  jTree Questions

    Hi
    I have looked through the forum and other articles for answers to my questions but I am still confused.
    In my SWING application I have a JTree which has Node Type binding on it and displays nodes corresponding to Master and Detail views.
    What is the best way to capture the value of selected Node that is after a button is clicked?
    Secondly what is the best way to create an empty unbinded JTree (When i try to add a JTree the default nodes such as colors, sports etc show up)?
    What is the best way to populate this JTree? (The new JTree will be populated using the selected values from the first JTree after a button is clicked.)
    Any help will be apreciated. I have no clue where to proceed.
    Thanks in advance

    See:
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
    Frank

  • JTree questions

    Hi!
    What is the "best practise" on trees:
    Where should you put the methods for adding / deleting / Changes nodes? (In the node-class itself?)
    Where should you put listeners?
    How is a tree painted in the fastest way when you have many nodes?
    Thanks in advance!

    Hello ekren
    Where should you put the methods for adding / deleting / Changes nodes? (In the node-class itself?)Don't add or remove subnodes in the parentnode directly ! Use the methods from den DefaultTreeModel, or you will have problems with the GUI (JTree).
    Where should you put listeners?This depends, what you want to do. The TreeModel for model-Events, the JTree for user-events. So what do you want to do ?
    How is a tree painted in the fastest way when you have many nodes?When you have a custom TreeCellRenderer, then pay attention to your code, because the "getTreeCellRendererComponent"-method is called very often !
    Cache resources, if needed, and don't perform time-expensive tasks !
    Hope it helps
    Freddy

  • Want JTree e.g. of populating data from database.

    I want ur JTree example of populating data from database, can u plz give me that eg.?
    Awaiting 4 ur reply.

    Hi,
    AFAIK, there is no direct approach to populate a JTree directly from a resultset. However, JTree can use a DOM tree as its model by using the adapter pattern. The procedure to do this is well-documented in the SUN website and the link is provided below. The code to convert a resultset to XML is provided below:
    protected void resultSetToXML(OutputStream out,
    ResultSet rs,
    String stylesheet)
    throws IOException, ServletException {
    // Create reader and source objects
    SqlXMLReader sxreader = new SqlXMLReader();
    SqlInputSource sis = new SqlInputSource(rs);
    // Create SAX source and StreamResult for transform
    SAXSource source = new SAXSource(sxreader, sis);
    StreamResult result = new StreamResult(out);
    // Perform XSLT transform to get results. If "stylesheet"
    // is NULL, then use identity transform. Otherwise, parse
    // stylesheet and build transformer for it.
    try {
    // Create XSLT transformer
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t;
    if (stylesheet == null) {
    t = tf.newTransformer();
    } else {
    // Read XSL stylesheet from app archive and wrap it as
    // a StreamSource. Then use it to construct a transformer.
    InputStream xslstream = _config.getServletContext().
    getResourceAsStream(stylesheet);
    StreamSource xslsource = new StreamSource(xslstream);
    t = tf.newTransformer(xslsource);
    // Do transform
    t.transform(source, result);
    } catch (TransformerException tx) {
    throw new ServletException(tx);
    The classes SQLXMLReader and other classes used in this example are available in the following java packages.
    import java.sql.*;
    import javax.sql.DataSource;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.sax.*;
    import javax.xml.transform.stream.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.AttributesImpl;
    The following is the link that explains how to load a JTree from DOM.
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPDOM6.html
    Cheers,
    vidyut

  • Populating values from popup

    Hi,
    Module pool program: I have 3 fields based one drop down select in the first field the 2nd filed values will get popup screen(F4), based on any row select here, those values should get into populate in 2nd and 3rd fields (table maintenance screen).
    Till Popup I have done.
    I am getting row values into an internal table but here i am facing problem is when i select row in popup only first field only populating the next field not getting.
    Please suggest me
    Regards,
    Prabhakar

    Hi Prabhakar,
    U said ur getting one field value from the popup. U can get the values that ur gonna show in popup in one internal table.
    Get the single field value from popup which the user selects into the program and using READ statement get the remaing values from the internal table for the same and update in the required place.
    Regards,
    Sanil

  • Adding popup menus on jmenuitem

    hello
    I would like to add a popup menu when right-click on a jmenuitem , given that the left click will launch the jmenuitem action.
    I've done this by invoking:
    jMenuItem.setArmed(false);
    when a right click is detected, so i bring up my popup and the action is not launched.
    But the jMenuItem hides himself and the popup stay in the middle of nothing (a bit ugly)
    QUESTION:
    how to tell the jMenuItem and the corresponding jMenu to stay visible while and after I use the popup ? Is it possible ?
    Thank you for any help,
    Xavier

    Repost...

  • Quick JTree Question

    Hello:
    Is there a way to set a treeNode that does not currently contain any childern with the closedFolderIcon instead of the leafIcon?
    Example:
    If I created a node that allows childern, but is currently empty, I would like to display this node with the closedFolderIcon. This would be similar to an empty directory within a file system.
    I plan on having a "Add Folder" and "Add Node" button to manipulate the tree.
    When I add a rootNode to the JTree I get a leafIcon instead of the closedFolderIcon. I only get the closedFolderIcon once I have added a childNode to the rootNode.
    Any ideas?
    Thanks,
    claude jones

    Please read my posting more carefully. My reply said it was based on my assumption that he wanted to affect the presentation of the nodes, not the definition of what it means to be a leaf node.
    In trees, a leaf node can not have children, ever. By his own posting, claude_jones said "a node that allows childern, but is currently empty". This is not a leaf node.
    He also says, that of this node, "I would like to display this node with the closedFolderIcon". The key word here is "display". Right there, that tells you wants to affect the presentation of the original data, not the original data.
    By the way, if you are still using DefaultTreeModel for your tougher tree problems, you might want to check out the JavaSoft tutorial on creating your own tree model classes. It makes a world of difference and makes your code a lot cleaner. If you're already familiar with this, I apologize.

  • Old items are not populated after adding items into a master/detail form

    Hi,
    I am relatively new to APEX. I am creating a master/detail form. It works well. When I add new items the older items are no more populated. Why ?
    For example I have an itme which is a select list as a Named LOV. At creation of the row I want the user to choose from this select list. It works well.
    But when modifying the record, I don't want the user to change this name. For that purpose, I create an item which is a display only item. This item is conditional and appear only when the record has been created.
    And this is where the problem comes. It seems to work but, if I logout of the application and login, then values are no more populated to the items and I get an error when trying to update the form.
    I hope I make it clear. I have been trying a lot of times and found that if I add items, then everything goes wrong.
    Thank you for your kind help.
    Christian

    Hi Christian,
    You don't say what the error is that you are getting - this may help us with your problem!
    On the form, do you now have TWO fields - one being the original select list and the other being a read-only version of it? Is it likely that BOTH fields could appear on the page at the same time AND that both are connected to the field on the table?
    You can set the select list to be read-only conditionally - in this case you could make it read-only on the condition of the primary key field not being null.
    Andy

  • Pb with populating newly added AD fields for existing users

    Hello,
    Let's say that we have version 10 of the AD process form pushed to production.
    Then we decided to push version 11 of the AD process form, which now has 4 more fields, to prod.
    For new users, we can see that the new fields are populated and the data flows down to AD.
    But, how do things work for existing users with existing AD account?
    How can we make the new fields appear in the process form of an existing user with old AD account that did not contain the new 4 fields.
    Thanks
    Khanh

    FVC or Form Version Control Utility is specifically designed for this purpose. Refer OIM documentation & also have a look at the following links:
    http://download.oracle.com/docs/cd/E10391_01/doc.910/e10363/appc.htm
    http://oim-iam.blogspot.com/2010/04/oim-fvc.html
    Thanks
    SRS

  • Question about Mac Pro and Adding GPU's

    I am a recent convert from PC and I had a Dell system that had two Nvidia Cards in it, but I could not use each one to run one monitor because it was SLI and it could only clone my screen and not extend it. So I had to plug both monitors into one card, and I basically paid for one card that I never really used since I wanted two monitors.
    I have two monitors hooked to my new Mac Pro, and my question is if I put in another Nvidia GT120 will each GPU run one monitor, and will they run as one big desktop just they way I have it set up now. Plus is there any benefit to having the dual GPU? I work on documentary videos and I use Adobe Creative Suite a lot. Will having the dual GPU speed up things like After Effects and Premiere. I know snow Leopard will help some, but in the mean time will an extra GPU help any?

    As Hatter said, you can drive 2 monitors from 1 video card on the Mac. SLI/Crossfire doesn't work under OSX, so unless you need to run more than 2 monitors, there's no need to have more than 1 video card...
    And I wouldn't say you got no use out of the 2nd video card in your dell. If you were gaming at all, you were probably getting better performance using the SLI than you would have gotten with just 1 card.
    So, yes, under OSX, you can drive 2 monitors with the 1 card and it will let you either clone the desktop on to both displays (both show the same thing) OR stretch the display so the desktop stretches across both displays...
    I'll be doing this with my mac pro to drive 3 monitors (using a 2nd video card)... Which should give me a HUGE desktop (I can't describe how much nicer it is to have tons of desktop space when programming or doing video editing...)

  • Easy JTree question

    I'm using something like the code below to "select" a node in my JTree. The node does get selected (an action is taken via the listener), however the node does not get selected in the graphical sense (i.e. the mouse selected node remains highlighted). How do I get the JTree to render the programatically selected node as the new selection?
      jTree.setExpandsSelectedPaths(true);
      jTree.setSelectionPath(jTreePath);
    ...Thanks

    you could try something like this if you had all your
    checkboxes named ina stuctured order I.E. checkbox_1, checkbox_2
    ect.
    countVar = 0;
    //if you had 10 checkboxes I.E. i<11
    add_btn.onPress=function(){
    for(i=1; i<11; i++){
    if(_root["checkbox_"+i].selected==true){
    countVar+10
    movieClip_mc.gotoAndPlay(countVar)
    }

  • Newbie Needs Help on adding popup/validation screen

    I have to create a procedure in a PDF that will ask the reader if they agree to follow the procedure when they try to close the PDF
    Sort of like a popup or validation screen when you load new software.
    So the screen would have a statement i.e., Do you agree to follow this procedure? then the reader would have to press a yes or no button which would be on the same screen as the statement and their answer would then be automatically e-mailed back to the originator.
    Can this be done in LivecycleES2?
    If yes, can you point me in the right direction. I have Padovas PDF Form Bible.
    I have done some javascript along with some PDF forms with radio buttons and e-mail Links
    The boss saw this popup screen at another company so he figures it can be done.

    Your email?
    I have done a sample for you.
    my email: [email protected]
    Nith

  • Adding popup before printing deliveries in VL01N / VL02N

    Hi,
    there´s a need to print deliveries in different languages, when the delivery is between inter company.
    In this case, a popup should be shown when printing deliveries in VL01N / VL02N. It should be shown,
    when choosing the message type, before starting to print.
    On this popup the language, in which the additional print out should be made, should be chosen.
    After that, the delivery should be printed in the original language and then in the chosen language.
    Is that possible and if so, how? Any other ideas?
    Thank you!

    Hi
    Yes u can, u need to change the print program (I suppose the std RVADDN01 or a copy of RVADDN01).
    U should change the routine PROCESSING in order to print the delivery twice: one with original language and one with the choosen language, something like this:
    FORM PROCESSING USING PROC_SCREEN.
      DATA: T_FIELDS TYPE TABLE OF SVAL WITH HEADER LINE,
            RETURNCODE.
      DATA: T_NAST  TYPE TABLE OF NAST.
      PERFORM GET_DATA.
      CHECK RETCODE = 0.
      APPEND NAST TO T_NAST.
      T_FIELDS-TABNAME      = 'NAST'.
      T_FIELDS-FIELDNAME    = 'SPARS'.
      APPEND T_FIELDS.
      CALL FUNCTION 'POPUP_GET_VALUES'
           EXPORTING
                POPUP_TITLE = 'Choose langue'
           IMPORTING
                RETURNCODE  = RETURNCODE
           TABLES
                FIELDS      = T_FIELDS.
      IF RETURNCODE IS INITIAL.
        READ TABLE T_FIELDS INDEX 1.
        IF NOT T_FIELDS-VALUE IS INITIAL.
          MOVE T_FIELDS-VALUE TO NAST-SPRAS.
          APPEND NAST TO T_NAST.
        ENDIF.
      ENDIF.
      CLEAR  NAST-SPRAS
      PERFORM FORM_OPEN USING PROC_SCREEN VBDKL-LAND1.
      CHECK RETCODE = 0.
      LOOP AT T_NAST INTO NAST.
    * Start form
        CALL FUNCTION 'START_FORM'
             EXPORTING
                  LANGUAGE    = NAST-SPRAS
             EXCEPTIONS
                  FORM        = 1
                  FORMAT      = 2
                  UNENDED     = 3
                  UNOPENED    = 4
                  UNUSED      = 5
                  SPOOL_ERROR = 6
                  OTHERS      = 7.
        IF SY-SUBRC <> 0.
          RETCODE = SY-SUBRC.
        ENDIF.
        CHECK RETCODE = 0.
        PERFORM CHECK_REPEAT.
        PERFORM HEADER_DATA_PRINT.
        CHECK RETCODE = 0.
        PERFORM HEADER_TEXT_PRINT.
        CHECK RETCODE = 0.
        PERFORM ITEM_PRINT.
        CHECK RETCODE = 0.
        PERFORM END_PRINT.
        CHECK RETCODE = 0.
        CALL FUNCTION 'END_FORM'
             EXCEPTIONS
                  UNOPENED                 = 1
                  BAD_PAGEFORMAT_FOR_PRINT = 2
                  SPOOL_ERROR              = 3
                  OTHERS                   = 4.
        IF SY-SUBRC <> 0.
          RETCODE = SY-SUBRC.
        ENDIF.
        CHECK RETCODE = 0.
      ENDLOOP.
      PERFORM FORM_CLOSE.
      CHECK RETCODE = 0.
    ENDFORM.
    Max

  • General JTREE question ...

    I'm creating a data-driven JTree. Changes to the JTree will be reflected immediately in the database. Also, the JTree might contain as many as 10,000+ elements.
    Should I buffer this in some type of data structure (e.g. a hashtable ) or should I just write directly to-and-from the JTree? Will performance take a hit?
    Thanks.

    Depends where the changes are coming from. If they are being keyed by a human operator, then propagating those changes directly to the database should not be a problem. At least I don't find it a problem, and my larger JTrees contain over 10,000 nodes. At any rate, I would not design a complicated buffering system until I found there was a problem for it to solve.

  • JTree question

    Hello !
    I need some help creating TreeNodes in a tree.
    first i will explain what i need.
    I have a string that look like this:
    d:\A dir\Another dir\file
    That string is the complete path ro a file. that path is stored in a database.
    I have no ideea how to create tree nodes that will look similar to:
    +d
    |- A dir
    |--- Another dir
    |-------file
    Can anyone help me in this one please >
    Thank you

    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display

Maybe you are looking for