Hi, I have a powertable setup to highlight a row when a certain tag value is found, the step index. I’d like the table to auto scroll to the highlited row automatically. I added this Jtable code to the propertyChange script area and it kind of works, but I’d like to make two improvements:
I can’t figure out how to get the rowIndex value into the property change script, I just used a manual number of 22 in the Jtable script, but I’d prefer to have the rowIndex value from the configureCell script that I used to change the rows background color to white.
The scroll bars are frozen once the Jtable script executes, I’d like to release the enable the scroll bars after the jtable auto scrolls once.
Here’s the propertyChange script
if event.source.StepIndexDynamic and event.source.StepIndexDynamic > 1200: #auto scrolls the powertable down so the active step is visible
jTable = event.source.getTable()
rectangle = jTable.getCellRect(22,0,0)
jTable.scrollRectToVisible(rectangle)
jTable = 0
if event.source.StepIndexDynamic and event.source.StepIndexDynamic <= 1200: #auto scrolls the powertable up so the active step is visible
jTable = event.source.getTable()
rectangle = jTable.getCellRect(0,0,0)
jTable.scrollRectToVisible(rectangle)
jTable = 0
Here’s the configureCell script:
ActiveCIPStepIndex = self.StepIndexDynamic #reads cip1 or cip3's step index , from the property change script
StepIndexColumnValue = self.data.getValueAt(rowIndex,"StepIndex") #gets the value from the tables StepIndex Column
if StepIndexColumnValue == ActiveCIPStepIndex: #searches for the active cip step number in the power table
return {'background': 'white'} #Highlites the active phase's step row
Here is the code I use for manipulating a power table scroll position: self.layout.getViewport().setViewPosition([Enter desired position here])
After rereading your post, I realized I misread it.
Perhaps this is what you are looking for:
if event.source.StepIndexDynamic and event.source.StepIndexDynamic > 1200:#auto scrolls the powertable down so the active step is visible
jTable = event.source.getTable()
rectangle = jTable.getCellRect(event.source.selectedRow,0,0)
jTable.scrollRectToVisible(rectangle)
jTable = 0
if event.source.StepIndexDynamic and event.source.StepIndexDynamic <= 1200: #auto scrolls the powertable up so the active step is visible
jTable = event.source.getTable()
rectangle = jTable.getCellRect(0,0,0)
jTable.scrollRectToVisible(rectangle)
jTable = 0
That didn't work, I don't think event.source.selectedRow is equal to the row index # of the row I changed its background color to white in the configure cell script.
I was able to get it to work by moving the rowIndex in the configureCell script into a custom property integer tag:
if StepIndexColumnValue == ActiveCIPStepIndex:
self.RowIndexCustomProperty = rowIndex
return {'background': 'white'} #Highlites the active phase's step row
Then the propertyChange script uses the RowIndexCustomProperty
One thing I noticed was the print command is constantly printing to the console, where i expected it to only print once when the StepIndexDynamic value changed. Is this going to waste resources having this script constantly execute?
You can't safely use the configureCell to change any data or change what is visible. It is called by Swing itself (indirectly) whenever Swing decides part of the table needs to be repainted. It might only be called for a subset of cells, depending on what is visible at that moment. Only use it to drive the proper display of the requested cell. It can be called for reasons totally divorced from a data change or selection change.
Confirmed, the script in the configureCell script was intermittently working, but it craps out occasionally, I moved the relevant part to the property change script, thx!