1

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)

Ding Dong
  • 13
  • 3

2 Answers2

0

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.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Thank you, MadProgrammer for your answer - it really helped me clarify in my mind the difference between a TableModel and a TableRenderer. My actual situation, though, ended up being much more convoluted! Oy! For future readers: I've left info below on what I had to do to fix my problem. Enjoy! – Ding Dong Jul 25 '12 at 14:40
0

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().

Ding Dong
  • 13
  • 3
  • 1
    Table.updateUI really shouldn't be used for this, it is related to the look & feel API. Did you try and use invalidate(), repaint()? And/or TreeTableModel.fireTreeNodesChanged(java.lang.Object source, java.lang.Object[] path, int[] childIndices, java.lang.Object[] children) ? – MadProgrammer Jul 25 '12 at 15:15
  • emphasizing @MadProgrammer 's point: using updateUI is **WRONG**! – kleopatra Jul 25 '12 at 16:38