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.

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.

  • Albums and events question

    Hi when I drag folders containing photos into Iphoto it creates an event. What I currently do is after the event is created, I select an event, I hit the + sign in the bottom left and create an album.
    I like having my albums on the left side for quick access to my library of photos. The problem is that if I add 30 folders, 30 events are then created.
    I have to manually create an album out of each event one at a time. Is there any way that once an event is created it automatically creates and album. So say that 10 events are created, 10 albums will appear on the left.
    If I select a couple events and hit the + option and hit create an album, it will only create one album out of the events selected. I would like to select multiple events at one time and have multiple albums created instead of just one. How do I do that?
    Is what I want to do possible? thanks

    Well let me answer a question with a question
    Why have all your Events mimicked in Albums? IF you can find the pic in an Event, you can find it in an Album.
    To say nothing of all the basics: If you have the year, month, day. Title, keywords, camera a model etc etc you can use any (and all) of these to find your pics too.
    To merge Events: Simply drag one to another in the iPhoto Window.
    Regards
    TD

  • 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.

  • Alter system set events Question

    Version 10202 on AIX
    sql> alter system set events '4030 trace name heapdump level 536870917; name errorstack level 3';
    Questions about this statement..
    what this command is doing, i guess creating tracefile for event 4030...& the location of trace file would be the current direcotry?
    & how to setup same kind of event trace for other events, any tips....& what to check in tracefile for problem?

    The values for level I have record are 1, 2, 3, 8, and 32 so I am guessing the number shown is the address of a specific heap to be dumped. The address of a heap would potentially change with a change in the shared pool storage parameters. Where did you get the address value?
    The dump should go to the user background dump destination and not the current directory.
    PS - if you have metalink look at document: #218105.1 Introduction to ORACLE Diagnostic EVENTS
    HTH -- Mark D Powell --
    Message was edited by: MDP add PS to Metalink Doc
    mpowel01

  • 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 :)

  • Click Event Question - VB6 SDK 6.5

    A quick question for you guys:
    On the A/R Invoice form, I have a UDF that exists as a combo box.  I can trap the et_COMBO_SELECT event on that combo box just fine, however, I would like to generate a click event on the 'Name' field on the main form from the UDF et_COMBO_SELECT event.  The problem I'm running into is that because the form that contains the UDF has a different UID from the actual A/R Invoice main form, I get an error when I try to perform the click event on the 'Name' field.  The code I'm using is below.  Any help would be appreciated.
    Thanks,
    Greg
    '(A/R Invoice) Change value of eqp_DivisionCode global variable when combo select event triggers
    If eqp_pVal.FormType = -133 And eqp_pVal.FormMode = fm_ADD_MODE And _
       eqp_pVal.ItemUID = "U_Division" And eqp_pVal.EventType = et_COMBO_SELECT Then
       Set eqp_frm = SBO_Application.Forms.Item(FormUID)
       Set eqp_cmbDivision = eqp_frm.Items("U_Division").Specific
       eqp_DivisionCode = eqp_cmbDivision.Selected.Value
    End If

    Hi Greg,
    if you want to access a User Defined Field on a System Form but in header level you need to approach it as follows:
    If (pVal.EventType = et_FORM_LOAD And pVal.FormType = 139 And _
        pVal.Before_Action = True) Then
            Set oform = m_App.Forms.Item(FormUID)
            Dim oUsrForm As SAPbouiCOM.Form
            Dim num As Long
            Dim UDFformUID As String
            num = Right(FormUID, (Len(FormUID) - 2))
            num = num + 1
            UDFformUID = "F_" & num
            Set oform = m_App.Forms.Item(UDFformUID)
            oform.Items.Item("U_1").Specific.String = "Test"
        End If
    Regards,
    Lisa Mulchinock
    SAP SDK Consultant
    Galway

  • Calendar Event Question

    I'm new to iPhone, coming from Blackberry. I would like to be able to schedule an event to repeat every five weeks and another event every four weeks. Is there a way to customize this? If not, can you recommend an app which will give me a reminder every four and/or every five weeks? Thank you!

    Sorry, answering my own question. It seems you have to do it on iCloud. Kind of frustrating if you're not on your computer but at least it's possible. Thanks for reading.

  • 10G event question

    Hello all
    I am coding Forms in 10G and i have an architectural question. If i am coding a form event with plsql that is not hitting the database how do i know that it is not making a call to the app server. I am worried about coding events that make too many calls back to the server which limits performance. I have coded in .NET and the ability to have events on everything is great for features but really bad for performance. I don't want to create features that are hindering performance due to round trips.
    thanx in advance

    Hi,
    good, question, that I don't have an answer for. I would assume it to be three round trips because the trigger fire in different times and as far as I remember Forms only bundles triggers that are on a specific item.
    Forms does not know whether or not PLSQL code is associated with a trigger and this currently is discussed internally at Oracle as well as here on the forum (some month ago).
    The outcome so far is that it is difficult to not ping the server about actions taking place on thw Forms client because it could be a navigation involved. This, if not reported back to the server, leads e.g. to the :system.cursor_item giving the wrong return value. As said, this is something we are discussing but haven't come to a conclusion.
    For you this means that no matter if there is a PLSQL code associated with a trigger, a network round trip is made. However, keep in mind that we are not issuing a round trip for all triggers on an item but bundle all triggers that fire to the same time (e.g. all POST triggers on an item will cause one roundtrip)
    Frank

  • 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.

  • URGENT----- JTree Event

    I have a JTree with parent node---- PARENT1.
    To it are added CHILDNODE1 and CHILDNODE2.
    Another parentnode PARENT2 with CHILDNODE3 CHILDNODE4.
    PARENT1 and PARENT2 added to ROOTNODE
    JTree is added to LHS of JSplitPane
    Similar to Explorer in Windows.
    Added listeners to JTree like this
    mTree.addTreeSelectionListener(new TreeHandler(this));
    mTree.addMouseListener(new TreeHandler(this));
    where TreeHandler is a class extending MouseAdapter and implementing TreeSelectionListener.
    Overidden public void valueChanged(TreeSelectionEvent aTreeEvent)
    by calling aTreeEvent.getPath() and from the obtained path, I determine PathCount and PathComponent.
    Based on this I display Panel on RHS of JSplitPane.
    I have a situation say CHILDNODE1 is selected and corresponding Panel is displayed. If I select CHILDNODE2 with mouse, I prompt for saving changes made to CHILDNODE1 panel...So I should reselect CHILDNODE1 in JTree programmatically and not CHILDNODE2
    I have used mTree.setSelectionPath(path_of_CHILDNODE1) .
    But the problem is it is triggering an event on selection of CHILDNODE1, which I donot want to. How do I stop this????
    and also will call to mTree.setSelectionPath(aPath) trigger a TreeSelectionEvent or my event handling is wrong ?
    Thanks in advance

    If I have understood clearly ur problem, When the other cell in the tree is selected the corresponding rHS componet will be updated is that right. And wht U wanna do is to holp updationg rhs before saving previous content.
    If that is right, then y dont U ask for the save option in the treeevent itself?i mean in the overridden value chnaged function

  • Iphoto Events Question

    This is probably a very easy question.
    If you have one event called Trips and drag photos out of that event into a few others to break them down into seperate events like Trips 2007 and Trips 2008, do the pictures you drag over to new albums get copied over so you can delete the original Trips event or does it just create a pointer from original event to new event?
    I just want to be sure so I dont have multiple copies of photos taking up space if I dont have to.
    Thanks in advance

    Patrick
    You need to be really clear on your Terminology for this one.
    do the pictures you drag over to new albums get copied over so you can delete the original *Trips event* or does it just create a pointer from *original event to new event* ?
    Are you talking about Albums or Events?
    When you drag from Event to Event the actual file is moved. Events in the iPhoto Window correspond exactly with the Folders in the Originals Folder in the iPhoto Library package file (Right click on it in the Pictures Folder -> Show Package Contents). You can move photos between Events, you can rename Events, edit them, create them, as long as you do it via the iPhoto Window. Check out the Info Pane (wee 'i', lower left) the name and date fields are editable. Edit a Event Name using the Info Pane, the Event Folder in iPhoto Library/Originals will also have the new name.
    When you add a photo to an Album it's a reference and not moving an actual file.
    So which are you talking about, Albums or Events?
    Regards
    TD

  • Events question can anyone help?

    I am brand new to the mac world...( bye bye PC forever!) I love it. I just have a quick question about iphoto events. I have my photos in events and I like that. when i double click on an event to open it up, I used to see thumbnails on the page of all events. For whatever reason, now when I go to open up a particular event it opens with one picture at a time. large pic. how do I get back to the thumbnails...I see thumbnails when I scroll over the event.....
    thanks! Nancy

    Nancy
    Welcome to the Apple Discussions.
    At the bottom right of the iPhoto Window is a slider. Drag it left.
    Regards
    TD

  • Postmerge session event question

    We have implemented a custom session event listener that utilizes the postmerge session event.
    We have observed some unexpected behavior and were hoping that the product architect or manager could explain this behavior.
    We have the following graph of objects:
    A has a many-to-many privately owned collection of B
    B in turn has a many-to-many privately owned collection of C
    After commiting a transaction involving object A we observe:
    postMerge event for A
    postMerge event of each of A's privately owned Bs
    yet NO postMerge event for any of B's privately owned Cs
    Questions:
    1) Is this the expected behavior?
    2) Since we need to do some processing of Cs, we are using the postMerge event that occurs on Bs to update the Cs. Is this a safe/correct approach?
    3) In a transaction that involved only updates to Cs, (no changes to A or B), would we see a postMerge event for each updated C?
    Thanks in advance for any clarification you can provide.
    ...Steve

    You could paste the results (tkprof ?) of the trace.
    The "missing" time could be an uninstrumented wait --- i.e. a wait event that is not captured in v$session_event. Particularly because you are using external calls.
    For example, see "Case Study 1" at http://blog.tanelpoder.com/2007/08/27/advanced-oracle-troubleshooting-guide-part-2-no-magic-is-needed-systematic-approach-will-do/
    Hemant K Chitale

  • Emailing calendar event question

    Is it possible to email a calendar event from my iMac to someone with an iPhone, so they can easily add the event to their calendar?  If I email an event, the outgoing message says:
    "To add it to your calendar, click the link below"
    But when they click the iCal...ics link in the email, nothing happens.  I know if I view the same email on my Mac in the Mail app and click on the link, I'm prompted to add the event to my calendar.
    -Thanks

    Sorry, answering my own question. It seems you have to do it on iCloud. Kind of frustrating if you're not on your computer but at least it's possible. Thanks for reading.

Maybe you are looking for