Question

I need to use a JavaFX 2.2 TreeView control inside a larger scrollpane that has several other elements which are not part of the Treeview. The problem is that TreeView has its own built-in scrollpane. Does anyone have an example of a way to turn off the built-in scrollpane so that the TreeView grows as large as the items contained within it?

Was it helpful?

Solution

While it is not currently possible to remove the scroll bars, it IS possible to mostly hide them with CSS.

.your-selector *.column-header-background *.show-hide-columns-button,
.your-selector *.scroll-bar:vertical *.increment-button,
.your-selector *.scroll-bar:vertical *.decrement-button,
.your-selector *.scroll-bar:vertical *.increment-arrow, 
.your-selector *.scroll-bar:vertical *.decrement-arrow {
    -fx-background-color: null;
    -fx-background-radius: 0;
    -fx-background-insets: 0;
    -fx-padding: 0;
    -fx-shape: null;
}

.your-selector *.scroll-bar:horizontal,
.your-selector *.scroll-bar:horizontal *.track,
.your-selector *.scroll-bar:horizontal *.track-background,
.your-selector *.scroll-bar:horizontal *.thumb,
.your-selector *.scroll-bar:horizontal *.increment-button,
.your-selector *.scroll-bar:horizontal *.decrement-button,
.your-selector *.scroll-bar:horizontal *.increment-arrow, 
.your-selector *.scroll-bar:horizontal *.decrement-arrow {
	-fx-base: transparent;
	-fx-background-color: white;
}

OTHER TIPS

This is a great question.

I think you need to create your own TableViewSkin which does not derive from the VirtualContainerBase. VirtualContainerBase manages a VirtualFlow, which you don't want if you want the entire TreeView to display. I believe this is a rather tricky thing to accomplish in a general way within the JavaFX 2/8 API and do not have any sample solution or further suggestions on how to accomplish this at this time.

There is an existing feature request for such functionality in the JavaFX issue tracker:

  • RT-26631 "Allow scrolling to be disabled on Controls like Table, List, Tree and TreeTable".

Currently, the feature has not been scheduled for implementation in a future release.

In my application I just wanted to remove the horizontal scrollbars. The answer of robross0606 was very useful to me, but it turns out only the following was necessary in my case:

.scroll-bar:horizontal,
.scroll-bar:horizontal *.increment-button,
.scroll-bar:horizontal *.decrement-button,
.scroll-bar:horizontal *.increment-arrow, 
.scroll-bar:horizontal *.decrement-arrow {
    -fx-padding: 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top