/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package tests; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.SplitPane; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; /** * * @author sjiang */ public class MySplitPane extends Application { public static void main(String[] args) throws Exception { Application.launch(args); } @Override public void start(Stage stage) throws Exception { final SplitPane sp = new SplitPane(); sp.setPrefSize(300, 300); sp.setDividerPosition(0, 0.25f); Rectangle rec1 = new Rectangle(50, 50); rec1.setFill(Color.RED); Rectangle rec2 = new Rectangle(50, 50); rec2.setFill(Color.BLACK); Rectangle rec3 = new Rectangle(50, 50); rec3.setFill(Color.BLUE); sp.setOnMouseClicked(new EventHandler() { @Override public void handle(MouseEvent me) { sp.getItems().add(new Rectangle(10, 10)); System.out.println("---jsl clicked to add a rectangle as a new item. Size="+sp.getItems().size()); } }); sp.getItems().setAll(rec1, rec2, rec3); Scene scene = new Scene(sp); stage.setScene(scene); stage.setVisible(true); } }