Forum Discussion

gxwheels152's avatar
gxwheels152
Occasional Contributor
3 years ago
Solved

Java Swing table - trouble setting a cell value

Our Application Under Test works extensively with Java Swing tables.

We have been able to click on cells and also extract values from table cells for checkpoint purposes.

But, we are having trouble Setting or Typing into a cell value. Here's what we've tried: 

  1. Recording a Keyword test and Playing it back (it records actual cells and fields within cells as objects and tries to update them). RESULT: no errors, but the cells are not updated
  2. Using the wValue [Set] on a designated Table and trying to Set the Text for a specific Cell. RESULT: no errors, but the cells are not updated
  3. Using the wValue [Set] on a designated CellRenderer and trying to Set the Text for a specific Cell. RESULT: received a "The parameter is incorrect" error, which makes sense as the CellRenderer doesn't offer up the wValue option when adding it in from scratch
  4. Using a script to access a cell within the CellRenderer and trying to Set the Text via the setText() function of the cell. RESULT: no errors and the setText() appears to be available, but also no update to the cells

I followed the principles outlined in the solution to this question about getting Cell Values using the CellRenderer and then checked if the setText() function is available, which it is. I then send in the desired value to the setText() function, but to no avail. 

Any help is much appreciated as our Application uses these tables extensively.

 

 

 

 

 

def setjTableCellValue(table, rowIndex, columnName, newValue):
  Log.Message("GLOBAL: You've are planning to update Cell Value to " + str(newValue) + " for Row: " + str(rowIndex) + " & Column: " + columnName )
  
  columnIndex = getjTableColumnIndex(table,columnName)
  tableObjectValue = table.getValueAt(rowIndex, columnIndex)

  Log.Message("GLOBAL: You've requested to updated the Cell Value for Row: " + str(rowIndex) + " & Column: " + columnName + " [" + str(columnIndex) + "]")
  
  renderer = table.getCellRenderer(rowIndex, columnIndex).getTableCellRendererComponent(table, tableObjectValue, True, True, rowIndex, columnIndex)
  Log.Message("GLOBAL: got the Table Renderer")

  if (aqObject.IsSupported(renderer, "setText")) :
    Log.Message("In the SetText Section")
    renderer.setText(newValue)

 

 

 

 

 

  • Here's the answer I discovered - when the setText() function is not opened up. Some feedback from the support desk & some additional trial and error helped connect the dots. 

    Hopefully this solution will help others as well

     

    Access Cells & Editing Tables in Java Swing

    1) access the cell in the manner appropriate for that cell:
       1a) DblClickCell
       1b) ClickCell

     

    This opens up the cell and any objects that are native to that cell.

     

    Objects we've seen within a cell:
       a) TextField
       b) Cell - used when a Date Picker Object is accessible for that field
       c) SuperComboBox with TextField & Button
       d) Filter Field - opened when clicking the SuperComboBox's Button

     

    You now mostly interact with objects within the activated cell. The Objects within the cell are now active because of step 1 above.
    There does seem to be 1 exception to this where you operate at the Table Level, using the Keys: "[Tab]" command. Step 3 has more details about that.

     


    2) Take the appropriate action for the objects in the cell, for example:
       a) SetText to change a Cell object
       b) Keys to update a TextField object
       c) ClickButton for a Button object
       d) Keys to type within a Filter Field object (filter field is part of a SuperComboBox)

    This maybe should have been obvious, but ... it's basically your typical OnScreen Actions once the cell and it's objects are active


    3) For Most fields -- simply hit the Tab key for the Table object in the following manner:
    EXCEPTION: see step 4 below
    NOTE: - hitting tab within our tables saves the action taken on the objects within the cell and moves you to the next cell or the next row
       a) Object - the Table
       b) Operation - Keys
       c) Value - "[Tab]"

    4) Tab out of a Sub-Objects when necesary -- If the Sub-Object is too deep or utilizing a common object as with the filter field (SuperComboBox) mentioned above, you must Tab out of the Sub-Object
       a) Object - the sub-object of the table's cell, e.g., the Filter Field
       b) Operation - Keys
       c) Value - "[Tab]"

     

     

     

1 Reply

  • gxwheels152's avatar
    gxwheels152
    Occasional Contributor

    Here's the answer I discovered - when the setText() function is not opened up. Some feedback from the support desk & some additional trial and error helped connect the dots. 

    Hopefully this solution will help others as well

     

    Access Cells & Editing Tables in Java Swing

    1) access the cell in the manner appropriate for that cell:
       1a) DblClickCell
       1b) ClickCell

     

    This opens up the cell and any objects that are native to that cell.

     

    Objects we've seen within a cell:
       a) TextField
       b) Cell - used when a Date Picker Object is accessible for that field
       c) SuperComboBox with TextField & Button
       d) Filter Field - opened when clicking the SuperComboBox's Button

     

    You now mostly interact with objects within the activated cell. The Objects within the cell are now active because of step 1 above.
    There does seem to be 1 exception to this where you operate at the Table Level, using the Keys: "[Tab]" command. Step 3 has more details about that.

     


    2) Take the appropriate action for the objects in the cell, for example:
       a) SetText to change a Cell object
       b) Keys to update a TextField object
       c) ClickButton for a Button object
       d) Keys to type within a Filter Field object (filter field is part of a SuperComboBox)

    This maybe should have been obvious, but ... it's basically your typical OnScreen Actions once the cell and it's objects are active


    3) For Most fields -- simply hit the Tab key for the Table object in the following manner:
    EXCEPTION: see step 4 below
    NOTE: - hitting tab within our tables saves the action taken on the objects within the cell and moves you to the next cell or the next row
       a) Object - the Table
       b) Operation - Keys
       c) Value - "[Tab]"

    4) Tab out of a Sub-Objects when necesary -- If the Sub-Object is too deep or utilizing a common object as with the filter field (SuperComboBox) mentioned above, you must Tab out of the Sub-Object
       a) Object - the sub-object of the table's cell, e.g., the Filter Field
       b) Operation - Keys
       c) Value - "[Tab]"