/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package helloworld; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.SplitPane; import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; /** * * @author jerome */ public class HelloSplitPane2 extends Application { private final SplitPane horizSplitPane = new SplitPane() { @Override public void layoutChildren() { if (getDivPosition() < 0.7) { setDivPosition(0.7); } else if (getDivPosition() > 0.8) { setDivPosition(0.8); } super.layoutChildren(); } }; @Override public void init() { } @Override public void start(Stage stage) { stage.setTitle("SplitPane"); final Button button = new Button("Add Button"); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { horizSplitPane.getItems().add(new Button()); System.out.println("Dividers: "); for (double pos : horizSplitPane.getDividerPositions()) { System.out.print(pos + " "); } System.out.println(); } }); horizSplitPane.getItems().addAll(button, new Button()); setDivPosition(0.7); // horizSplitPane.getDividers().get(0).positionProperty().addListener(new ChangeListener() { // // @Override // public void changed(ObservableValue observable, // Number oldPos, Number newPos) { // if (newPos.doubleValue() < 0.7) { // setDivPosition(0.7); // } else if (newPos.doubleValue() > 0.8) { // setDivPosition(0.8); // } // } // }); Scene scene = new Scene(horizSplitPane, 400, 400); stage.setScene(scene); stage.show(); } private void setDivPosition(double pos) { horizSplitPane.getDividers().get(0).setPosition(pos); } private double getDivPosition() { return horizSplitPane.getDividers().get(0).getPosition(); } public static void main(String[] args) { Application.launch(args); } }