0

I found here some similar questions, but none of them seem to be a solution to my problem.

How can I access the different panes in the structure of a scene?

The goal would be:

I have a split pane in the scene, which is put on to a border pane. In the left anchor pane of the split pane I would like to have an accordion. The right side should display a scene according to the chosen menu point of the accordion.

So if it would be possible to set a scene into the right side of the split pane it would be good, because than I could change this scene. Changing the whole scene is not a very good solution, cause the accordion won't be opened there where it was, and the app consumes too many fxml files.

Is it possible to only change the right side of the split pane, or is my approach completely wrong?

I found here how to get all Nodes in a scene, but it didn't bring me further.

Please give me an advice if you have experience with it, thanks!

user3435407
  • 1,019
  • 4
  • 15
  • 31

1 Answers1

1

Assuming you just have two nodes in the split pane, you can replace the second (right) one with

splitPane.getItems().set(1, newNode);

(Update)

If your SplitPane is defined in an FXML file, you will need to do this in the controller. To get access to the split pane, just give it an fx:id attribute (in SceneBuilder this is in the "code" section in the right panel) and use an @FXML annotation to inject it into the controller:

FXML file:

<!-- imports omitted -->
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.MyController">
   <SplitPane fx:id="mainSplitPane">
      <!-- ... -->
   </SplitPane>
</AnchorPane>

MyController.java:

package com.example ;

// imports omitted...

public class MyController {

    @FXML
    private SplitPane mainSplitPane ;

    @FXML
    private void handleButtonPress() {
        Node newNode = ... ;
        mainSplitPane.getItems().set(1, newNode);
    }

    // ...
}
James_D
  • 201,275
  • 16
  • 291
  • 322
  • Hi James, first thanks for your help again! It sounds good what you write, but I don't know how to pack out the splitPane. I get a Pane from FXMLLoader. But this Pane is a complex hierarchical structure, created in Scene Builder. So the issue is, that I don't know how to get to the splitPane to call the method you mention. Do you see what I mean? – user3435407 Feb 22 '15 at 23:46
  • so, for example, now I load an anchor pane, which contains the split pane. If I collect all nodes, and print them out, i get: SplitPane@4a1593[styleClass=split-pane] SplitPaneSkin$Content@1ba997e AnchorPane@874e0d SplitPaneSkin$Content@ec97d2 AnchorPane@d6471e SplitPaneSkin$ContentDivider@131394b[styleClass=split-pane-divider] SplitPaneSkin$ContentDivider$1@118c130[styleClass=horizontal-grabber] – user3435407 Feb 22 '15 at 23:51
  • Do this in the controller; just set the `fx:id` on the `SplitPane` so that you can access it there. – James_D Feb 23 '15 at 01:48
  • ok, I don't know this technique jet but I check it out, I let you know when I figured out how it works – user3435407 Feb 23 '15 at 01:53
  • There's basically no way to do anything at all with FXML unless you use a controller class. See the ["Controllers" section of the Introduction to FXML](http://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#controllers) and (less useful) the last section of the [Oracle tutorial](http://docs.oracle.com/javase/8/javafx/fxml-tutorial/fxml_tutorial_intermediate.htm) – James_D Feb 23 '15 at 01:58
  • No, the controllers I know, I don't know this fx:id. Until now I used the controllers for the buttons only, so the handleXY methods an such... But I check it out, it just takes a while – user3435407 Feb 23 '15 at 02:10
  • yeee! :) fully got it! Now I see better what's the connection between SceneBuilder and fxml and other parts! cheers! it was a big help! (i can't yet upvote tho) – user3435407 Feb 23 '15 at 02:54