0

I am trying to make things so that when I programmatically and/or manually select a given item in the tree (column 1, left-most column) it automatically scrolls horizontally in column 1 only to show the item (if the item is too wide for column 1 it should scroll so that the start of the item's string is positioned up against the left of the control).

The first step would be to understand what possibilities if any there are for somehow setting a ScrollPane for this first column. I tried in SceneBuilder to insert a ScrollPane between the TreeTableView and the first TreeTableColumn. I wasn't surprised that this didn't work.

I really hope the answer to this is not "impossible"! Given the nature of trees and the fact that sub-items must be indented to the right by some distance for each depth, it seems a pretty essential element of functionality/design of this (otherwise wonderful) control!

mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • If I understand correctly, it sounds like you need to use a custom `TreeTableCell` which uses a `ScrollPane` and then set the cell factory of the column. Unfortunately that will put a `ScrollPane` in each (non-empty) cell, rather than the whole column, which doesn't seem to be exactly what you want. Using selected state, however, you could hide any scroll bars when the cell/row isn't selected. – Slaw Mar 29 '20 at 18:13
  • Thanks for the suggestion. Oh dear, I was suspecting this would be the case. I can see how your helpful suggestion would at least be some answer to the default behaviour (i.e. "..." at the right), but if the underlying component itself doesn't scroll ... White space, too much white space! I'm new to JavaFX really but maybe there will be scope for forking the control to implement this at some distant point in the future. Sigh. – mike rodent Mar 29 '20 at 18:28
  • Someone more knowledgeable with the internals of `TreeTableView` (e.g. kleopatra?) may be able to suggest a workaround. – Slaw Mar 29 '20 at 18:38
  • Yes, I'd like to hear her views on it. Maybe it might be possible by extending `TreeTableColumn`. It would be distinctly non-trivial: you have to keep the selection changes aligned between all columns, and if one is wrapped in a `ScrollPane` (even if only horizontal scrolling is permitted), I can see this being a "nice" challenge. – mike rodent Mar 29 '20 at 18:45
  • 1
    Well, it'd be more complicated than that. Controls use "skins" to implement the visuals. As far as I know, there is no dedicated column regions in a tree-table view (or table view) in the default skin implementation. There's simply rows filled with cells laid out in such a way as to _look_ like a column. Even with that setup it might be possible implement per-column horizontal scrolling, but I don't know if you could gain enough access to build off of the existing implementation. Worst case scenario, you'd have to build the tree-table view skin from scratch (which is very much _non-trivial_). – Slaw Mar 29 '20 at 18:49

0 Answers0