2

My JavaFX layout has a TabPane. Each tab contains an AnchorPane and, inside of this one, a SplitPane. What I want to achieve is this: make the SplitPane not resizeable by using setMouseTransparent(true). That is clearly working, but as the JavaDoc pinpoints:

If true, this node (together with all its children) is completely transparent to mouse events. When choosing target for mouse event, nodes with mouseTransparent set to true and their subtrees won't be taken into account.

This represent an issue to me, 'cause I've got nodes inside of my SplitPane which I want to be able to interact with (i.e.: buttons; ...). Looking around I've found a couple of well answered questions about similar issues, both of them hinting to use node.setPickOnBounds(false) on the parent node. In my case, the parent would be the SplitPane.
Too bad, this is not working for me.

First of all, those are the two questions I've read about:
JavaFX: How to make a Node partially mouse transparent?
Mouse Events get Ignored on the Underlying Layer

Secondly, a screenshot of my JavaFX scene:

SplitPanes

Lastly, a code snippet of my JavaFX controller.

public class MainViewController extends AbstractController implements Initializable {

    @FXML private SplitPane splitPanelConnectionSettings;
    @FXML private Button buttonStartApache;
    @FXML private Button buttonStartMySQL;
    @FXML private Button buttonStartDataParser;

    @Override
    public void initialize(URL url, ResourceBundle rb) {

        splitPanelConnectionSettings.setMouseTransparent(true);
        splitPanelConnectionSettings.setPickOnBounds(false);

        buttonStartApache.setOnAction((event) -> {
            // Creating a new FXML object and binding to it the relative "*.fxml" resource file.
            FXMLLoader loader = new FXMLLoader();
            fxmlLoader(loader, FXML_START_APACHE_POPUP_PATH);
        });

        buttonStartMySQL.setOnAction((event) -> {
            // Creating a new FXML object and binding to it the relative "*.fxml" resource file.
            FXMLLoader loader = new FXMLLoader();
            fxmlLoader(loader, FXML_START_MYSQL_POPUP_PATH);
        });

        buttonStartDataParser.setOnAction((event) -> {
            // Creating a new FXML object and binding to it the relative "*.fxml" resource file.
            FXMLLoader loader = new FXMLLoader();
            fxmlLoader(loader, FXML_START_DATA_PARSER_POPUP_PATH);
        });

        buttonResetLastMessageID.setOnAction((event) -> {
            // Creating a new FXML object and binding to it the relative "*.fxml" resource file.
            FXMLLoader loader = new FXMLLoader();
            fxmlLoader(loader, FXML_RESET_LAST_MID_POPUP_PATH);
        });
    }

    ...

}

Using

splitPanelConnectionSettings.setMouseTransparent(true);
splitPanelConnectionSettings.setPickOnBounds(false);

doesn't look to do the job. The SplitPane is not resizeable, but all of its children are not clickable, even if I've set setPickOnBounds to false. Any hints?

Davide3i
  • 1,035
  • 3
  • 15
  • 35
  • 3
    If you don't want it resizable, why use a `SplitPane`? Even if you do use `SplitPane`, a more natural way of making it non-resizable is setting the min and max sizes of the children... You are trying to use `MouseTransparent` for something it wasn't meant to do... – Itai Feb 14 '18 at 11:13
  • Mostly for the look and feel. I'll follow your hint about using min and max sizes for the children. Thank you! – Davide3i Feb 14 '18 at 11:19
  • 4
    I'm a big believer in using features of a toolkit for their intended purpose, and generally writing code where the intention is clear. The primary purpose of a `SplitPane` is to allow the user to resize portions of the UI by dragging the mouse: if you don't want that, don't use a `SplitPane`. The provided mechanism for defining the "look" of a JavaFX UI is via CSS. So use a `GridPane`, add three `Region`s for the borders you want between the components, and use CSS to style those regions so they look like split pane dividers (or generally look the way you want). – James_D Feb 14 '18 at 12:58
  • Ok, thank you. I'm a new user of JavaFX, so I'm still getting into all the functions and mechanisms. – Davide3i Feb 14 '18 at 13:46
  • 1
    If you really want to enforce this behavior, you _can_ get the `Dividers` of the `Splitpane` and add a `ChangeListener` to their `position`, in which you reset the new value to the old value. But just because you can, doesn't mean you should. – Markus Köbele Feb 14 '18 at 15:37

0 Answers0