Forum Discussion

jmcwhinney's avatar
jmcwhinney
Contributor
10 years ago

How to double click TreeNode in JTree (Java applet)

Hi, I am able to get the required node from the jtree, but cannot figure out how to click on it.

Any help would be appreciated,

Thanks!

- James






var MenuBrowserTree =



 



Aliases.browser.BrowserWindow.FrameTab.tabpage.ShellDocObjectView.browser.JavaPluginControlWindow.frame1.panel1.RootPane.null_layeredPane.null_contentPane.DockableHolderPanel.MainDockingContainer.DefaultDockingManager_DockedHiddenSlidingContainer.DockedHiddenContainer.ContainerContainer.DockedFrameContainer.Panel.ContainerContainer.ContainerContainer.FrameContainer.erp.RootPane.null_layeredPane.null_contentPane.ScrollPane.Viewport.Tree;



var CurrentNode = GetNode(MenuBrowserTree.getVisibleRootNodes(),"Service Management");



CurrentNode.expand();



CurrentNode = GetNode(CurrentNode.children(),"Service Quotation/Contracts");



CurrentNode.expand();



CurrentNode = GetNode(CurrentNode.children(),"Service Quotations");





//CurrentNode.DblClick(); (This part doesn't work)


6 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi James,

     


    What exactly doesn't work? If you get an error message, please post its text here.


     


    I suggest that you read the "Java Swing Tree Support" article - it contains the info about how to test the Java Tree control in TestComplete.

  • Hi Tanya,



    The .DblClick() command effectively did nothing.





    I think the issue is that when TestComplete gives me a reference to an object (in this case my tree), then I can use the .Click() and .DblClick() functions.



    However, if I want to click on a specific child/leaf node in the tree, and I use my tree reference to manually get other object references beneath it (the nodes within the tree), I cannot use the .Click() and .DblClick() functions on those child objects.

    At that point, I can only use the child objects own methods.

    It seems I would have to instead call the tree's event handler at that point, which requires using additional classes and I haven't figured out how to do that in test complete yet.





    For example, when I record my actions into a script, it appears as:


    Aliases.browser.BrowserWindow.(etc etc etc).Tree.Click(122, 104);



    And this works fine.



    However If I then use the Tree's own methods to get a specific node in the tree like in the example below, I cannot click the child node:

     



    Aliases.browser.BrowserWindow.(etc etc etc).Tree



    .getFirstNode().Click();





    I can get the node just fine, but the Click() function doesn't work.  I think this is because the Click() function is not actually a method of the tree or the tree nodes, it is a method that testcomplete is somehow overlaying, and since testcomplete didn't give me the reference to the node, it isn't there.



    So, to summarize, how would you suggest I go about clicking on the specific tree node once I have found it?



    Thanks!


     



     


  • Here is another example:





    I have created a function that takes a reference to my table, and then sets a filter in the tables header:



    SetColumnFilterByLabel(XGrid, ColumnLabel, NewFilterValue);





    This way I can ensure I am always updating the right filter, even if the order of the table columns changes.

    (So my script will be more reliable).





    My function identifies the target field it wants to update (MyField), and then sets the filter value successfully using .setText().



    This works, h
    owever, .setText() doesn't trigger the table to refresh etc.  I need to send the TAB or Enter key to exit the field properly so the application refreshes the table.



    I cannot use the .Keys("[Tab]");   function because TestComplete did not give me the reference to this specific field, I obtained the field reference  programmatically.





    As a workaround, I have tried to trigger the  JTextField's update event using the below code:





    MyField.dispatchEvent(new KeyEvent(XGrid.getTopLevelAncestor(),KeyEvent.KEY_TYPED, 0, 0, KeyEvent.VK_UNDEFINED, 'H'));




    However I receive the following error message:

    "Microsoft JScript runtime error.  'KeyEvent' is undefined"



     


  • oh I found this article and now I am so close I think...

    http://support.smartbear.com/viewarticle/55546/








    var



    MyKeyEventParam1 =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.KeyEvent.KEY_TYPED;



    var MyKeyEventParam2 =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.KeyEvent.VK_UNDEFINED;



     



     



    var MyKeyEvent =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.KeyEvent(TheFrame,MyKeyEventParam1, 0, 0, MyKeyEventParam2, 'H');



    MyField.dispatchEvent(MyKeyEvent);


  • getting closer thanks to this page:

    http://www.coderanch.com/t/330281/GUI/java/Creating-Key-Event-Component



    But still unable to send the tab key.  It is failing on the last line.

    "Microsoft JScript runtime error.  Type mismatch"






    var



    MyKeyEventParam1 =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.KeyEvent.KEY_PRESSED;



    var MyKeyEventParam2 =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.KeyEvent.VK_UNDEFINED;



    var MyKeyEventParam3 =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.KeyEvent.VK_TAB;



    var MyKeyEvent =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.KeyEvent(MyField, MyKeyEventParam1, 0, 0, MyKeyEventParam2, MyKeyEventParam3);



    var AE =



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.ActionEvent(MyKeyEvent,Sys.Process("java").JavaRuntime.JavaClasses.java_awt_event.ActionEvent.ACTION_PERFORMED, "" );



     



     



    Sys.Process("java").JavaRuntime.JavaClasses.java_awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(AE);