Francois
Francois

Reputation: 626

How to modify horizontal scrolling behavior after hitting TAB in JavaFX TableView?

I'd like to change horizontal scrolling behavior in JavaFX TableView.

First, as context, I added the following key events:

  1. When user hits TAB, cell on the right of current cell becomes new current cell. When at the very last column of the line, hitting TAB again will select the very first column on the next line. If current cell is in last row and last column, hitting TAB will select cell in first row and first column.
  2. Inverse behavior is implemented when hitting SHIFT-TAB. Instead of going right, it goes left.

This behavior was easily implemented, playing with indexes and using TableView.scrollToColumn() and TableView.scrollTo().

The behavior I want to modify only occurs when a TableView has more columns then the number of columns that can be displayed. I would like to change scroll behavior when current cell is in the far right displayed column. Actually, hitting TAB will scroll to next column, but this new current column will become first displayed column on the left.

Instead, I'd prefer that hitting TAB when current cell is in the far right column displays next column as the last displayed column (far right) instead of first displayed column on the left.

This is exactly actual behavior when SHIFT-TAB is pressed. Going left displays newly selected column as the first displayed column. I'd like to replicate this behavior when going right in a TableView.

Any clues how to do it?

Regards.

Upvotes: 0

Views: 258

Answers (1)

jewelsea
jewelsea

Reputation: 159566

This answer isn't a full answer to your problem but you only requested clues for a solution, which is what this is and it is easier to put this as an answer rather than as a series of comments.

Possible solutions:

  1. Modify the table view behavior input map.
  2. Remap the key events routed to the table.

Perhaps you might need a combination of some of the above to get what you want.

1. Modify the table view behavior input map

This is the solution suggested by kleopatra in comments:

try to tweak the mappings in the inputMap installed by the table's behavior

For a bit more info on the behavior implementation, see the answer to:

It includes a link to the current behavior source and information on how you might go about tweaking it for your application.

The implementation of this approach is a little tricky because it is part of the internal com.sun API for JavaFX, which perhaps should not be directly used, as your application may break without warning in future JavaFX versions if you use it.

2. Remap the key events routed to the table.

Perhaps the technique of filtering input events in this answer:

might help you get the solution you want. However, again, I'm not sure.

You would need to do more work than that solution.

In addition to filtering the tab key, you would need to fire off a new artificial event to create shift+tab event.

And you would need to ensure that the filtering is done at the appropriate level (the capturing of the event for focus handling for tab might be at the scene level rather than the table view itself).

Upvotes: 1

Related Questions