Forum Discussion

pjaju's avatar
pjaju
Occasional Contributor
14 years ago

Fire events when Jtable cell is clicked

I am using TestComplete 8. I need to know how do I release/fire application events when i click on a JTable.

5 Replies

  • Hi,



    Events are fired automatically. Clicking from TC works in the same way as manual clicking does.
  • pjaju's avatar
    pjaju
    Occasional Contributor
    Thanks. However, my problem is little more complex. Let me give you an example - There is a dialog box which have 2 single column tables (named available columns and selected columns). The first table contains a list of names - which can be moved to selected columns table. Now assume that the selected column table is currently empty and I move 3-4 columns from first table. When i click on the selected columns table, it throws NPE. The reason being - when the selected column table is populated, two buttons (move up and move down) are supposed to be activated (they are used to re-arrange the selected column list). Please see the attached screenshot. The basic problem is that these buttons are not getting the notification of getting enabled.



    I want to emulate the manual clicking of the table so that all the events/notifications are fired correctly.
  • Hi,



    OK, exactly how do you add columns to 'Selected Columns' and how do you click on it in your test? Can you post here a script?
  • pjaju's avatar
    pjaju
    Occasional Contributor
    To select column, simply click on the item from Available columns list. This will enable the [>] button. Click it to move the selected item to Selected column list. Please refer to the screenshot (in earlier post).



    Here is a sample code:

    sub test()

       Dim arrayProperties, arrayValues, availableColumns, selectedColumns, leftMoveButton, rightMoveButton, closeButton, ctr, aCol

       

       'Captute all relevant objects on the dialog box

       arrayProperties = Array("JavaFullClassName", "AWTComponentName")

       arrayValues = Array("com.swing.table2.BaseTable", "nonFrozenTable")

       Set availableColumns = Get_Object_By_Property(Aliases.JAVA_Explorer.TableColumnChooser,arrayProperties,arrayValues,25)

          

       arrayProperties = Array("JavaFullClassName", "Name")

       arrayValues = Array("com.swing.table2.BaseTable", "SwingObject(""BaseTable"", """", 0)")      

       Set selectedColumns = Get_Object_By_Property(Aliases.JAVA_Explorer.TableColumnChooser,arrayProperties,arrayValues,25)  



       Set leftMoveButton = Get_Object_By_Property(Aliases.JAVA_Explorer.TableColumnChooser,"AWTComponentAccessibleName","<",25)

       Set rightMoveButton = Get_Object_By_Property(Aliases.JAVA_Explorer.TableColumnChooser,"AWTComponentAccessibleName",">",25)

       

       arrayProperties = Array("JavaClassName", "AWTComponentAccessibleName")

       arrayValues = Array("YButton", "Close")

       Set closeButton = Get_Object_By_Property(Aliases.JAVA_Explorer.TableColumnChooser,arrayProperties,arrayValues,25)

       

       'selectedColumns.selectAll()

      

       'Move required columns to selected columns

       Call closeButton.doClick

    end sub



    Note in the highlighted code - here the application throws NPE. I tried to simulate user click on the table, but again it threw NPE. The reason being, when selectAll is used via our script, the application fails to enable the MoveUp or MoveDown button (refer to screenshot)
  • Hi,



    OK, it got more clear now. It looks like you either need to use a native method of your control to fire the needed event after calling selectAll to make your control process the item selection (this mostly depends on your particular control), or select items without selectAll in the way a user would do this manually. For example, you can send a keyboard shortcut, which will select all items, to your control.