How can I determine if text is selected in a Java Table?

I have a java table which optionally contains one or more selected rows of some unknown text (by unknown, I mean I don’t know in advance any of the possible content).

How can I determine (without reading and parsing the entire table) if any rows are selected?

Additional Info:
I can use the Copy Selected Text, with ContinueOnError. This works, but this takes about 6 seconds before it times out (even though Timeout is set to 100 ms), when there is no selected text to copy. Can this timeout be reduced to under 1 second?

1 Like

Could you please show some screenshots? @grosner

Because we need to first understand what do you mean by selected here, does the table have a checkbox or any other way of selecting rows?

A selected row is one that has been clicked with the mouse left button, or shift clicked with the mouse left button, or otherwise selected with a ctrl-a. There are no check boxes.

Hello @grosner

It would be better if you can share a screenshot of the row which you are trying to extract

What I want to know (true or false) is whether one or more rows in a Java table are selected.
If rows are selected, then return true otherwise false.

For example, the window in the image below has one row selected.

I DO NOT KNOW in advance:

  • If there will be any rows showing in the table.
  • How many rows may exist in the table (0-???)
  • How many rows are selected

As mentioned above, the Copy Selected Text activity does capture the selected rows (or nothing if no rows are selected), but this activity takes too long to run (6 seconds) for my needs.

Did you tried Data extraction and Datatable. Rows.count to get the number of rows extracted

That gets all the rows. Exactly how could I determine how many rows are selected?

Is there a possibility to filter those in the application itself??? Any filter available?

There is no way to filter in this Java application.

For standard Swing tables, the selected cells will have the state selected in their javastate property. For non-standard tables, additional changes (in our code) might be needed.

Thank you Vlad. I could not see the selected attribute until the tooltip revealed the setting.

Note: It would be helpful if this were an expandable text field so the entire value could show (on 4k monitors) without the need for a tooltip.

Now that I know the javastate property exists, how can I check each row in the table without extracting the data (the extracted data does not appear to include the javastate attribute).

@gheorghestan FYI

What about checking the javastate attribute for selectors with the last tag . You can use a while(true) loop and break when the selector gets invalid.

@vlad.coteanu Thank you for your useful suggestion.

I was able to detect selected rows exist in my java table. I used an Element Exists activity with the following selector value.

I used the following RegEx that returns a match only if the word “showing,” exists in the javastate.

RegExCasePattern = “^enabled,focusable,visible,(showing,)?selected,active,transient”

Additional Information:

Initially, I thought “visible” indicated whether the value was shown on screen, but it turned out that “showing” was the determining if the selected row was displayed onscreen. I believe that this web page, about Class AccessibleState, documents the difference between “showing” and “visible” field values.

Again, Vlad, thank you for you guidance.

1 Like