JavaFX 8, how to hide a pane in Splitpane?
Asked Answered
I

1

9

I have a splitpane created from FXML that consists of Three panes left to right. I want to be able to hide the rightmost pane but I can't find anything to hide it. If I turn of the visibility it hides the pane content. What I want is to temporarily hide it, so the pane is removed visually.

As a temporary workaround I move the divider to 100%, but this leaves the divider visible. Another side-effect is that if I resize the main window the divider doesn't stay at the rightmost position.

Any tips on hiding one pane in splitpane?

Or any tips on the best way to achieve this without splitpane(rightmost pane needs to be resizable when not hidden). General pointers to techniques/containers would be appreciated since I'm new to Java/JavaFX but not to programming :)


Idomeneus answered 7/12, 2014 at 22:9 Comment(0)
I
16

Seems I've found it, even thought it's not a plain hide/show deal. My splitpane is named "mainSplitPane", and the one I want to hide/show is the third. Upon initialization of the controller I retrieve the third pane and store it in "componentsPane".

Declared in controllerclass:

Node componentsPane;

Called in initialize method of the controllerclass:

componentsPane=mainSplitPane.getItems().get(2); 

Code to hide:

mainSplitPane.getItems().remove(componentsPane); 

And code to show:

mainSplitPane.getItems().add(2, componentsPane); 
mainSplitPane.setDividerPosition(1, 0.8); 

A side effect is that I have to set dividerposition since it's removed.

Idomeneus answered 7/12, 2014 at 23:8 Comment(1)
Just an addon to the answer, before removing the componentsPane, get the divider position and store it, so when we maximize(add the componentsPane) again, the divider position will be retained as wellKarelian

© 2022 - 2024 — McMap. All rights reserved.