This discussion is archived
8 Replies Latest reply: Feb 25, 2013 10:25 AM by JPeredaDnr RSS

SplitPane not resizable

biochemistry43 Newbie
Currently Being Moderated
I have an interface that I have distributed several SplitPane but want these SplitPane not be resized or modified.

How I can do?

It is worth saying that the split pane is built with FXML.

Thanks in advance
  • 1. Re: SplitPane not resizable
    jsmith Guru
    Currently Being Moderated
    Use a VBox or an HBox instead of a SplitPane.
  • 2. Re: SplitPane not resizable
    biochemistry43 Newbie
    Currently Being Moderated
    I understand what you say but when I started building the GUI, was totally ignorant of Java FX and I built my entire GUI with Split-pane (as in the video Issuetrackinglite).

    However, the implications of making the interface with another layout are something serious.

    There is some other way to get what I want without having to remove the split pane?
  • 3. Re: SplitPane not resizable
    biochemistry43 Newbie
    Currently Being Moderated
    Any idea?
  • 4. Re: SplitPane not resizable
    ytw Explorer
    Currently Being Moderated
    Would placing a transparent node over the SplitPane work?
  • 5. Re: SplitPane not resizable
    biochemistry43 Newbie
    Currently Being Moderated
    how do I do that?
  • 6. Re: SplitPane not resizable
    jsmith Guru
    Currently Being Moderated
    Sample for making a split pane which is not resizable.
    I'll leave it up to you to transfer the concepts and apply them to your fxml based UI.
    import java.util.*;
    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.control.*;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class StaticSplitPaneExample extends Application {
      public static void main(String[] args) { launch(args); }
      @Override public void start(Stage stage) throws Exception {
        SplitPane split = createSplitPane();
    
        stage.setScene(new Scene(new Group(split)));
        stage.getScene().getStylesheets().add(
          getClass().getResource("static-split.css").toExternalForm()
        );
        stage.setResizable(false);
        stage.show();
    
        disableDividers(split);
      }
    
      private SplitPane createSplitPane() {
        SplitPane split = new SplitPane();
        split.getItems().setAll(
          createStackedButton("One"), 
          createStackedButton("Two"), 
          createStackedButton("Three"),
          createStackedButton("Four")
        );
        split.setDividerPositions(0.3, 0.6, 0.9);
        split.getStyleClass().add("static-split");
        split.setMinSize(500, 200);
    
        return split;
      }
    
      private void disableDividers(SplitPane split) {
        for (Node divider:  split.lookupAll(".split-pane-divider")) {
          divider.setMouseTransparent(true);
        }
      }
    
      private StackPane createStackedButton(String buttonText) {
        final StackPane stack = new StackPane();
        stack.getChildren().add(new Button(buttonText));
        stack.setStyle("-fx-background-color: cornsilk;");
        
        return stack;
      }
    }
    Associated css file to remove handles from dividers.
    /** static-split.css */
    .static-split .split-pane *.horizontal-grabber { -fx-background-color: transparent; }
    .static-split .split-pane *.vertical-grabber   { -fx-background-color: transparent; }
  • 7. Re: SplitPane not resizable
    biochemistry43 Newbie
    Currently Being Moderated
    thank you very much ... worked very well
  • 8. Re: SplitPane not resizable
    JPeredaDnr Newbie
    Currently Being Moderated
    Hi, I've found really interesting your solution to lock the splitpane, as there's no public access to SplitPaneSkin$ContentDivider.

    As you've pointed out in your code, you must call disableDividers method after showing the stage, otherwise lookupAll(".split-pane-divider") returns an empty set.

    I had to display a locked splitpane in a complex scene only when the user selected it, so after loading the splitpane on the scene I called disableDividers(), but without success.

    I was going to ask you for any clue on this, but as usually happens, writting the question I've found the answer..., so I post it in case anyone faces the same problem.

    Just put the call in the JavaFX Application Thread, as it's related with the UI update:
    private void disableDividers(final SplitPane split){
    
       Platform.runLater(new Runnable() {
    
            @Override
            public void run() {
                for(Node div: split.lookupAll(".split-pane-divider")){
                    div.setMouseTransparent(true);
                }
            }
        });
    
    }

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points