JXTreeTable - manipulating checkboxes from an external application - possible?
-
21-06-2021 - |
문제
Using Java code, I am tying to manipulate another, external Java swing application, for which I have no access to any information about how it was coded. Specifically, I am trying to manipulate a JXTreeTable. One of the columns, of type Boolean, contains checkboxes.
One thing I've tried to do, is to do code a double-click-then-space-bar action, which has worked. However, my manager would like me to figure out a way to toggle the checkboxes without using the spacebar.
I'm wondering – does anyone know a way to toggle the checkboxes using Java methods, despite me being blind to the original application's design? I've tried to use setCellData() with a Boolean parameter. Oddly, calling getCellData() onto the cell right after returns the value I modified it to, but the checkbox itself does not get toggled – plus, when submitting the form, it's the value reflected by the checkbox that's sent in, not the Boolean in the cell.
In addition, the checkboxes in the Boolean column carry labels. I have a feeling these labels are generated by the TableRenderer, but how can I grab the values on the labels?
Note: I am executing all the Java code through an automating testing script that I am writing (in QTP, to be exact). So, I am limited in a lot of the approaches I can use (e.g. I can't code my own custom Java classes)
해결책
Assuming that the column data is backed by a boolean value in the data model, change the values in the data model.
Just make use you fire the required table changed event so that the UI can update.
다른 팁
This is how I ended up fixing my problem:
My particular situation, though, ended up being much more complicated, as I have now found out. It turned out that modifying the model directly had no effect - I had to do all my table changes via the actual node objects in the tree. Through blindly tracing methods, I discovered the developers had coded custom node handlers, with methods to both change the checkbox status and the data in the model. To update the table display, I used treeTable.updateUI().