Programmatically Set Selected Cell in Power Table

I’m trying to set a cell to being selected with programming. I’ve tried using the below code and many variations to no avail.
I’ve also tried to bind the Selected Column and Selected Row properties to a value, but it doesn’t work.

t = event.source.parent.getComponent("Power Table")getTable() 
t.addSelectionInterval(1,1) 

I’ve also tried this within a button:

event.source.parent.getComponent('Power Table').selectedRow = 1
event.source.parent.getComponent('Power Table').selectedColumn = 1

Some code that I used on a personal project:

target = self.parent.parent.getComponent("Data")
ds = target.viewDataset
for row in range(ds.rowCount):
	if ds.getValueAt(row, 0) == time:
		target.getTable().getSelectionModel().setSelectionInterval(row, row)
		target.getTable().scrollRowToVisible(row)
		break
2 Likes

I follow the logic, but not sure how to re-appropriate it to fit my needs. I have two custom properties on my table, and I want the selected column and selected row to reflect those. Why are the selected column and selected row properties bindable, but it doesn’t do anything when bound? I tried this on a button and it did not do anything

target = event.source.parent.getComponent('Power Table')
target.getTable().getSelectionModel().setSelectionInterval(1, 1)
target.getTable().scrollRowToVisible(1)

They’re bindable only because any integer property is ‘bindable’, even if setting it will not reflect changes back. Sending changes back to the table is more complicated because of the potential for conflicts between a ‘model’ and a ‘view’ index, further complicated by things like sorting and filtering.

I’m not sure why your test code isn’t working - does your power table match these settings?:

1 Like

Sure does, no luck. Let me try a different method… How can I pull in my custom properties on the table (rowRef and colRef) into the configure cell function, and make it look like it is selected? This is really just to reflect the row and column pointers anyways.

EDIT: That test code did work on selecting a row I thought the row selection was allowed but it was unchecked. Now how to select a single cell…

To select a single cell, make sure you have column selection allowed, then set a specific row and column interval:
https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setRowSelectionInterval(int,%20int)
https://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html#setColumnSelectionInterval(int,%20int)

1 Like

HA!! Got it

target = event.source.parent.getComponent('Power Table')
target.getTable().changeSelection(1,1,0,0)

this selects cell 1,1

1 Like

table =event.source.parent.getComponent(‘Power Table’)

initialselRow =event.source.parent.getComponent(‘Power Table’).selectedRow

table.setSelectedRow(initialselRow + 1)

this will select row downwards

Have noticed that to use the onRowsDropped feature to drag a row from one table to another, you have to first select the row by clicking on it, release it so it is added to the selectedRows and then click on the same row again to drag it. Doesn’t seem like a big deal, but the schedulers keep saying they can’t drag work orders on the schedule table. I was hoping I could use the above logic to add to the selected rows in the onMousePressed() extension function, but it doesn’t seem to update whatever object is needed for the onRowsDropped to work on the other table.

How can I make onRowsDropped work with a single click and drag?