import java.util.Random; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.SceneBuilder; import javafx.scene.control.ScrollPaneBuilder; import javafx.scene.input.KeyEvent; import javafx.scene.layout.VBox; import javafx.scene.layout.VBoxBuilder; import javafx.scene.paint.Color; import javafx.scene.shape.RectangleBuilder; import javafx.stage.Stage; import javafx.stage.StageBuilder; /** * * @author akouznet */ public class Bug extends Application { public static void main(String[] args) { launch(args); } private VBox vBox; private Random r = new Random(); @Override public void start(Stage stage) throws Exception { StageBuilder.create() .scene( SceneBuilder.create() .width(300) .height(300) .onKeyPressed(new EventHandler() { @Override public void handle(KeyEvent t) { vBox.getChildren().add(RectangleBuilder.create() .width(r.nextInt(150) + 50) .height(r.nextInt((int) vBox.getHeight() / 3 + 10)) .fill(Color.rgb(r.nextInt(256), r.nextInt(256), r.nextInt(256))) .build()); } }) .root(ScrollPaneBuilder.create() .pannable(true) .content(vBox = VBoxBuilder.create() .build()) .build()) .build()) .applyTo(stage); stage.show(); } }