Power Table - change enter function

Is there a way to change the function when a user hits the enter button with a row selected in a power table? The default is to move down the next row. I would like to change it to add the focused row to the selected rows. Thanks!

I see that the normal tables have event handlers for key pressed functions. Is there something similar for the power tables?

A little bit hacky, but perhaps on a propertyChange event on the power table, you coul:

  1. Use an if statement to check if the propertyName is “rowSelected”.

  2. Check if newValue is 1 greater than the old value. This would mean that the default “move down to the next row” has just occured.

  3. If step 2 is true, select the row from the data property of the table using the oldValue (the row highlighted when the enter key was pressed) and add it to the selected rows.

I would say to then set the selectedRow property of the Power Table to the oldValue, but this would probably cause your event script to fire again resulting in an infinite loop.

You can access the underlying Java table by running self.getTable() in an extension function (perhaps in the initialize function, but you must know that the initialize is only ran when opening the page).

After that, it should be possible to alter the key bindings like it’s done on a regular Java table, but I can’t help on with that.

This here does about the same, but for click handlers on the header: Catching click and right-click events on power table headers

	from javax.swing import KeyStroke, JTable, AbstractAction
	from java.awt.event import KeyEvent
	enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)
	tableComponent = self
	table = tableComponent.getTable()
	enterPressed = "EnterPressed"
	class EnterAction(AbstractAction):
		def __init__(self,tc):
			self.tc = tc
		def actionPerformed(self, e):
			print "Enter pressed on row: ", self.tc.selectedRow
	table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(enter, enterPressed)
	table.getActionMap().put(enterPressed, EnterAction(tableComponent))
1 Like