/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package test; import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.effect.DropShadow; import javafx.scene.input.MouseEvent; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.util.Duration; public class VBoxDirty extends Application { private static VBox createRow(final VBox list) { final VBox item = new VBox(); final Label text = new Label("Click any of the rows"); item.getChildren().add(text); // these styles make it nice, they are not needed for the bug to appear item.setStyle("-fx-background-color: gray; -fx-padding: 10;"); // effect is needed, without the shadow it works fine item.setEffect(new DropShadow()); item.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent event) { clear(list); // this animation is needed, without it it works fine TranslateTransition tt = new TranslateTransition(Duration.millis(2000), text); tt.setFromX(0); tt.setToX(10); tt.play(); shiftAllBelow(list, item); } }); return item; } private static void shiftAllBelow(VBox list, VBox row) { boolean found = false; for (Node child : list.getChildren()) { if (found) { child.setTranslateY(0); TranslateTransition tt = new TranslateTransition(Duration.millis(2000), child); tt.setToY(50); tt.play(); } if (child == row) { found = true; } } } private static void clear(VBox list) { for (Node i : list.getChildren()) { i.setTranslateY(0); } } @Override public void start(Stage stage) { VBox root = new VBox(); Scene scene = new Scene(root, 600, 600); // this is needed otherwise the rows will be shifted out of the root // VBox which makes the whole thing dirty root.setPadding(new Insets(60, 60, 60, 60)); for (int i = 0; i < 10; i++) { final VBox row = createRow(root); root.getChildren().add(row); } stage.setScene(scene); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } }