I have a problem with the SplitPane
inside a ScrollPane
.
I need an extendable scrollPane similar to the TableView
so when I have too many items I have scrollbar, when all of my items are visible then hide the scrollbar.
ScrollPane has a switch : fitToHeight
but both true/false doesn't do the job I need.
I will upload two screenshots to show what I mean.
If it is set to true
then I simply don't have the scroll which is not a solution because I may have too much data to fit in one window so I need the scroll.
If it is set to false
then I always have scrollbar even if there is no data to show at the bottom of the view.
I would like to be the scrollbar dynamic, so when I drag the last divider and there is no space to fit the last item, the scrollbar should appear, when there is space for every item in the SplitPane
then it should not be displayed.
Any idea how can it be achieved?
The relevant code:
Fxml:
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.VBox?>
<ScrollPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fitToWidth="true"
fx:controller="test.Controller">
<SplitPane fx:id="splitPane" orientation="VERTICAL">
<VBox spacing="5" minHeight="20">
<Label text="*Title*" VBox.vgrow="NEVER"/>
<TextArea VBox.vgrow="ALWAYS"/>
</VBox>
<VBox minHeight="20" spacing="5">
<Label text="*Title*" VBox.vgrow="NEVER"/>
<TableView VBox.vgrow="ALWAYS">
<columns>
<TableColumn/>
</columns>
</TableView>
</VBox>
<VBox minHeight="20" spacing="5">
<Label text="*Title*" VBox.vgrow="NEVER"/>
<TableView VBox.vgrow="ALWAYS">
<columns>
<TableColumn/>
</columns>
</TableView>
</VBox>
<VBox minHeight="20" spacing="5">
<Label text="*Title*" VBox.vgrow="NEVER"/>
<TextArea VBox.vgrow="NEVER"/>
</VBox>
<padding>
<Insets topRightBottomLeft="5"/>
</padding>
</SplitPane>
</ScrollPane>
Controller:
public class Controller implements Initializable {
@FXML
private SplitPane splitPane;
@Override
public void initialize(URL location, ResourceBundle resources) {
splitPane.setDividerPositions(0d,.33d, .66d,1d);
}
}
Main:
public class Main extends Application {
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("View.fxml"));
ScrollPane pane = loader.load();
primaryStage.setScene(new Scene(pane, 800, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Here I have the scrollbar even if there is no need to scroll, every item is visible
Here I don't have the scrollbar