JTree listener question

Hi,
What are the TreeListener/TreeModel methods that would be called if I
1. double click on a row
2. expand/collaps a node
Thanks in advance.
Olek

A quick summary:
TreeModelListener
treeNodesChanged
treeNodesInserted
treeNodesRemoved
treeStructureChanged
TreeExpansionListener
TreeWillExpandListener
ExpandVetoException
TreeSelectionListener

Similar Messages

  • JTree Updating question

    Hi there. I have two questions.
    I have a data structure that is being displayed in a JTree, so I made a Model and it works great. The data structure can be updated from non-gui interaction. The nodes don't change position or anything, its just the data that is displayed is changed. I handle it currently by calling a function in the model I made called nodesChanged(), which basically does the following:
    public void nodesChanged()
        int len = treeModelListeners.size();
        TreeModelEvent e = new TreeModelEvent(this, new Object[] {rootItem});
        for (int i = 0; i < len; i++) {
          ( (TreeModelListener) treeModelListeners.elementAt(i)).treeNodesChanged(e);
      }It does actually work, the changes are reflected in the JTree, but it seems a little expensive, and the updates to the actual data model could come at about 150 per second. To deal with that now, I just use a timer class that updates it about every 3/10's of a second, which does a pretty good job, but is there a more elegant way to do this? Something where the node is an observer of the data in the data structure (which are Observable objects)?
    The second question I have is when I do the above, sometimes the display name of the node will be larger than the value it had previously, but the Textbox (if that's what it is) doesn't grow, so I get a ... at the end.
    For example, if I have "Run" and it changes to "Stopped", it will show up as "Sto...".
    Any help would be great. TIA.

    well, you can start by making the node you put in the tree model event the lowest node in the tree that needs updating, instead of root.
    I don't know about the timer thing, cuz as far as I know, the listener will invoke code that will refresh the renderers, as opposed to painting where repaint calls can be merged into one. If you aren't getting that many updates all the time, you could implement something where the listener fires to an intermediate listener which will fire the info to the tree after a slight delay. That way if you get multiple updates, you can effectively ignore lots of them.
    The ... thing, I thought that treeNodesChanged was the appropriate method, although maybe it has to be for the specific node, not root.

  • JTree sizing question...

    Hello:
    I have a JTree for which each cell contains a button. I have written a renderer that renders the button, and I realize that I have to do some special stuff to capture a click on the button. My question is unrelated to all of that.
    The problem is that over time, the labels on my buttons change (and may become longer (wider)), but the tree size does not change. In fact, when I update the button label and the tree is re-rendered the rendering of the button gets "chopped off". I've put the tree in a scroll pane, but this doesn't help - the right side of some of the buttons get cut off to the original tree size. I've tried lots of different variations on setPreferredSize, calling repaint, etc, and am not having any luck. I've put together a demonstration of this behavior in a smallish application that I'm posting here, where I create a 2 node tree with buttons that read "Hi", then I change the button labels to "Goodbye" and re-render. You'll see that the button's are cut off about halfway through the button.
    In case its important - I'm running java version 1.5.0_07 on a 32-bit Linux box.
    Any help would be greatly appreciated. Thanks in advance!
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    public class JTreeQuestion
      public static void main(String [] args)
        JTreeFrame f = new JTreeFrame();
        f.pack();
        f.setLocation(30, 30);
        //Draws buttons with "Hi" (short string)
        f.setVisible(true);
        ButtonNode.updateString("Goodbye");
        //Draws buttons with longer string, buttons get "cut off"
        f.repaint();
    class JTreeFrame extends JFrame
      JTree tree;
      JScrollPane treeView;
      public JTreeFrame()
        super("My Tree");
        DefaultMutableTreeNode root;
        root = new DefaultMutableTreeNode(new ButtonNode());
        root.add(new DefaultMutableTreeNode(new ButtonNode()));
        tree = new JTree(root);
        tree.setCellRenderer(new ButtonNodeRenderer());
        treeView = new JScrollPane(tree);
        add(treeView);
    class ButtonNode
      public static String str = "Hi";
      public static void updateString(String inStr)
      { str = inStr; }
      String getStr()
      { return str; }
    class ButtonNodeRenderer extends DefaultTreeCellRenderer
      public Component getTreeCellRendererComponent(JTree tree,
                              Object value, boolean sel, boolean expanded,
                              boolean leaf, int row, boolean hasFocus)
        Box theBox = new Box(BoxLayout.X_AXIS);
        super.getTreeCellRendererComponent(tree, value, sel, expanded,
                                           leaf, row, hasFocus);
        DefaultMutableTreeNode jtreeNode = (DefaultMutableTreeNode)value;
        theBox.add(new JButton(((ButtonNode)jtreeNode.getUserObject()).getStr()));
        return (theBox);
    }

    For those who are interested. The DefaultTreeModel has a method named nodeChanged() that tells the tree model that a specific node has changed, and the model re-interprets the cell causing its sizse to change as necessary, so that the full button is rendered now.
    Basically what I did was instead of calling repain, I call a method that I wrote that loops through all the tree nodes, indicates they have changed, then repaint's, and it all works out. My trees are relatively small, so this is fine, but if others face the same problem, you'll probably want to selectively indicate which nodes have changed so the tree model doesn't have to do more work than necessary.

  • 10g listener question

    Hi
    All,
    First question
    When I do some minor modification in tnsnames.ora. Do I Need to stop and start listener again.
    Second question
    And If I want to stop and start listener Do I need to stop all the databases before I can stop and start listener ? (9i and 10g)
    Thanks,
    Vishal

    When I do some minor modification in tnsnames.ora. Do I Need to stop and start listener again.No, tnsnames.ora is totally independant to the listener.
    And If I want to stop and start listener Do I need to stop all the databases before I can stop and start listener ? (9i and 10g)No, the listener is used only to connect new client to the server, once the connection is done, listener is not used anymore for that connection.
    Note you can reload instead of stop and start the listener.
    Micolas.

  • JTree image question

    I have a question about using images in a JTree.
    I have like 2 parent nodes who both have a lot of child nodes now i know how to get an image for every node but how do i get 1 image for 1 parent with all his children and another image for the other parent with his children.

    It is a programming problem because i dont know how to give echt DefaultMutableTreeNode his own picture. You should think of it like msn when you log in your contacts are in a Tree and your offline contacts have a red icon and online contacts have green one. I need to to the same for my program(chat program). But i can't figure out how but i know how to give alle the DefaultMutableTreeNode's a picture but i cant give individual one's a picture.
    I hope i cleared things up :)

  • JTree#expandRow() Question

    JTree tree;
    //etc...
    1) /** Expand the tree */
    for (int i=0; i<tree.getRowCount(); i++)
         tree.expandRow(i);
    and tree.getRowCount() = 6
    2) /** Expand the tree */
    for (int i=0; i<6; i++)
         tree.expandRow(i);
    My tree has 6 rows, and each row has its own sub-tree hierarchy.
    I wonder why the first case will expand the whole tree, which includes
    the subtrees of each row.
    But in second case, it only expands the first 6 rows in the tree.
    So basically the question is why (1) and (2) have different tree view outputs??

    Well, after you expand row 1, the row count isn't 6 anymore, is it? It's something larger than that, depending on how many children the first node has.

  • 11.2.0.3 upgrade to 12.1.0.2 - listener question

    I am currently doing a database upgrade from 11.2.0.3 to 12.1.0.2. The server has a number of other 11g database instances which have not yet been upgraded and the listener on teh server is 11g. Should i be creating a 12c listener for the upgrade i.e. having two listeners on the same server or what's the best way to tackle this scenario? thank you.

    You don't need the 12c listener for the upgrade. Create the 12c listener.ora file, but do not start the listener. Once the upgrade completes, shut down the 11g listener and start the 12c listener.
    Alternatively, install the 12c binaries, create the 12c listener.ora file, shutdown the 11g listener, start the 12c listener, then perform the upgrade.

  • Another RAC Listener question

    Hi all
    Would anyone be able to point me in the right direction as to trouble shoot the following. On one of my RAC nodes I am getting the following.
    When I run: srvctl status listener
    I get
    PRCR-1035 : Failed to look up CRS resource for ora.listener.type
    PRCR-1068 : Failed to query resources
    Cannot communicate with crsd
    When I run: lsnrctl services listener
    I get
    LSNRCTL for 64-bit Windows: Version 11.2.0.2.0 - Production on 13-JUN-2011 14:55
    :00
    Copyright (c) 1991, 2010, Oracle. All rights reserved.
    Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
    The listener supports no services
    The command completed successfully
    Thanks to anyone who can point me in the right direction.

    Hi there - please see below:
    Node2:
    CRS-601: Internal error
    RC: 11, File: clsCheckParser.cpp, Line: 907
    CRS-4000: Command Check failed, or completed with errors.
    CRS-4535: Cannot communicate with Cluster Ready Services
    CRS-4000: Command Status failed, or completed with errors.
    Node1:
    CRS-4537: Cluster Ready Services is online
    CRS-4529: Cluster Synchronization Services is online
    CRS-4533: Event Manager is online
    A Big list of reourceses appears for the status resource command for Node 1
    Thanks

  • JTree event question

    Hi,
    I am facing a problem and hoping somebody here can give me a clue.
    I have a JTree in my application, which has different types of nodes (all implement TreeNode ). One node there needs lazy-loading, what I want is when user clicks either '+' or folder icon/label then this node gets updated. I have added MouseListener to the tree, it works fine with clicking folder icon or label but not for clicking '+'. I also tried adding other listeners like TreeWillExpand etc. but it not seems a good solution to me since I just need to treat one node defferently.
    There are a couple of options I think can help:
    - catch clicking '+' event for specific node
    - display '+' even folder has no child (just for one node)
    - or disable '+' for this node
    Thank you in advance

    Well, after you expand row 1, the row count isn't 6 anymore, is it? It's something larger than that, depending on how many children the first node has.

  • ORA - Listener question!!

    Hi Friends,
    In the listener.ora parameter is set to ADMIN_RESTRICTIONS_LISTENER = ON
    To rotate the log without having to download the listener, we need these restrictions are in 'OFF'.
    Is it imperative for the proper functioning of SAP on Oracle ADMIN_RESTRICTIONS_LISTENER is in 'ON'?
    Thanks in advance.
    Martin Sello

    > In the listener.ora parameter is set to ADMIN_RESTRICTIONS_LISTENER = ON
    Ok....
    > To rotate the log without having to download the listener, we need these restrictions are in 'OFF'.
    What? "Download" the listener?
    Why would you need to have the ADMIN_RESTRICTIONS off in order to get a new listener log file?
    How about just restarting the listener?
    (I mean you are the DBA of this machine and you know the password, don't you ? )
    > Is it imperative for the proper functioning of SAP on Oracle ADMIN_RESTRICTIONS_LISTENER is in 'ON'?
    Nope, SAP does not know about this setting.
    In fact no Oracle client would ever know about it.
    It's a server side setting.
    It's just about the listener.
    cheers,
    Lars

  • JComboBox listener question

    Hi,
    I was wondering what kind of listener I would use to detect enter being pressed in a JComboBox.
    I tried an actionListener but this sends actionEvents at far too many times, I want to limit what I'm doing to only when the user presses enter in the JComboBox.
    It seems rather odd that a keyListener can't be used with a JComboBox, or at least according to the API specifications...
    All help is very appreciated!!

    The JComboBox itself just has the text field and then the down arrow, correct? Like if I am writing in that text field I am writing in the JComboBox? Basically all i need is a way to do something when the user presses 'enter', but not when all the other various things that trigger ordinary action events are fired. Using a keyListener to find out whether the key pressed was 'enter' seemed like the best way to do this, but if key events aren't even getting sent when the focus is in the text portion of the JComboBox that may not be the case. If there's anyway i can explain the problem better I'd be happy to do so.
    Thanks

  • JTree path question

    I have created a program that basically simulates single celled organisms in a random (non graphical) world, and I want to use a JTree to show the family history and allow the user to bring up an organism's stats by clicking on in the the Jtree, but I have a problem. Each organism has a unique ID number (starting at 0) and that's what I want to display on the tree. I have the code working to add the new organisms to the root, but I want them added as a child to the parent (each child has only one parent for these organisms), but I don't know how to do it. I tried using insertNodeInto but since everything after the root is dynamically generated I don't know how to identify the parent correctly (just using the ID doesn't seem to do anything). Do I need to create a method that somehow copies the entire treemodel into a collection and steps through it? I have the organisms in a collection already (an arraylist to be exact), so I could figure out the lineage by stepping through that, but then how do I build a 'selection path' object that will work to tell Java exactly where I want the child to go? Is the selection path just some kind of array, or is it even possible to build a selection path without a user clicking on a tree node? I hope you can figure out what I'm trying to say here and I appreciate any help you can give.

    Start by creating a Map that has your organisms as the key and the nodes they are in as the value. Or just let the organism include a reference to the node that contains it. Either of those would allow you to identify the TreeNode that contains a particular organism.

  • Jtree - beginner question

    hi,
    i wanted to build a jtree and have started the swing tutorial on it, seems small, but i wanted to know is it easy to build a jtree to map the file system? something like windows explorer? i wanted to build a ftp utility and wanted to show the local and remote drives and file systems in a scroll pane, so i was thinking about using a jtree, first time i've had to use it, so i'm a little new to it.
    Thank you.

    Search Google for "java file explorer"
    --A                                                                                                                                                                                                                       

  • JTree Icon question

    Currently, ALL leaves in the JTree are displayed with a certain icon that looks like a piece of paper. What should I do if I want only leaves at depth 4 to have the piece of paper icon and all the rest to have folder icons even if they are leaves?
    Thanks

    I guess a custom renderer is in order.
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display

  • JTree Important Question

    Hi All,
    in the JTree, is there a way to change the root handles
    icons, not through the UIManager?
    I need the Changes to apply only for the one instance.
    is there a key for the putClientProperty method?
    a work around through the TreeCellRenderer is possible to
    write, but seems as a bit of a waste.
    10x in advance

    OK. If "handle" means the leftmost icons, that is the little circle with a dash pointing right or down under Java L&F, or either a + or a - in a square under Windows & Motif L&F, they are NOT part of the node display, and so they are not dealt with by a renderer. They are completely L&F dependant (while the leaf, open, closed are renderer dependant, and the L&F just provides some "hint" to the default renderer). It is possible that some L&F would display trees in a completely different way, without handles. So this is the tree UI delegate business, not the renderer's.
    You can set the icons for the application globally by setting UIManager properties Tree.expandedIcon and tree.collapsedIcon. (you knew that already). The good news is that the UI delegate seems to get these icons once sometime when it is created, rather than asking the UIManager each time it needs them.
    I tried
        Object previousExpanded = UIManager.put("Tree.expandedIcon", myExpandedIcon);
        Object previousCollapsed = UIManager.put("Tree.collapsedIcon", myCollapsedIcon);
        tree2 =  new JTree(data);
        UIManager.put("Tree.expandedIcon", previousExpanded);
        UIManager.put("Tree.collapsedIcon", previousCollapsed);.
    There is a tree1 created before and a tree3 afterwards, and it works fine, that is only tree2 get my icons.
    I tried to go a little farther, as I am not sure when the ui delegate might get reset. So I wrote a descendant of JTree to do the job in updateUI.
    public class CustomHandleTree extends JTree {
      // republish ancestor non-default constructors
      Icon expanded = null;
      public void setExpandedIcon(Icon anIcon) {
        expanded = anIcon;
        updateUI();
      // do the same for collapsed
      public void updateUI(){
        Object defaultExpanded = null;
        if (expanded != null)
          defaultExpanded = UIManager.put("Tree.expandedIcon", expanded);
         // collapsed stuff too
         super.updateUI();
        if(expanded != null)
          UIManager.put("Tree.expandedIcon", defaultExpanded);
         // collapsed stuff too
    }It works too, and I can even set the handles dynamically, when clicking on some button. It refreshes properly.
    The bad news is that I found that by trial and error, and have no single line of documentation to explain why it should work.
    Hope it helps nevertheless.
    Regards.

Maybe you are looking for

  • Using XML File As Target- Data Integrator (SAP BODI Tool)

    I am trying to populate records to an XML File from a table. The XML schema has a node say 'Address'. When I run my job, I get duplicate records in the output XML File. For example: under the element address, the fields are address1 and addres2 then

  • Where to download Acrobat SDK?

    Hello, friends, Where to download Acrobat SDK? I was brought to the download page, http://www.adobe.com/cfusion/entitlement/index.cfm?e=acrobat%5Fsdk Acrobat Developer CenterAcrobat 8.1 SDK Acrobat 8.1 SDK is now available free of charge to all users

  • CAPTURE WINDOW DOESN'T OPEN IN CS5

    Premiere CS5 seems to be working, but for the capture window will not open at all.  so i can't import video into the program Thanks [Personal info removed.] Message was edited by: Jim Simon

  • Introducing a dynamic table but when I preview it got an error

    I have the database connected, the recordset declared but when I introduce the dynamic table I can view it on the index.cfm file then I preview it in IE7 and I got an error. This is my first time please be patient. Thanks

  • Issue on deleting error message in WebUI

    Hi Experts, I have deleted one standard error message in DO_PREPARE_OUTPUT  with some condition in header level but I am having below issues. Issue one : Now error is not showing in webui  at header overview screen but  allocated space for that error