/* * Copyright (c) 2016, 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 hello; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Slider; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class HelloPriorityOrder extends Application { private boolean added = false; @Override public void start(Stage stage) throws Exception { stage.setTitle("Hello PriorityOrder"); final Slider slider = new Slider(-2, 2, 0); slider.setDisable(true); final Rectangle wheatRect = new Rectangle(150, 150, Color.WHEAT); wheatRect.setId("Wheat"); wheatRect.setOnMousePressed(e -> System.out.println("Mouse Pressed: Wheat"/* + e */)); wheatRect.relocate(50, 30); wheatRect.priorityOrderProperty().bind(slider.valueProperty()); final Pane rectsPane = new Pane(); final Rectangle redRect = new Rectangle(150, 150, Color.RED); redRect.setId("Red"); redRect.setOnMousePressed(e -> System.out.println("Mouse Pressed: Red"/* + e */)); redRect.setPriorityOrder(0); redRect.relocate(20, 10); final Rectangle greenRect = new Rectangle(150, 150, Color.GREEN); greenRect.setId("Green"); greenRect.setOnMousePressed(e -> System.out.println("Mouse Pressed: Green"/* + e */)); // Test styling greenRect.setStyle("-fx-priority-order: -1;"); greenRect.relocate(100, 50); final Rectangle blueRect = new Rectangle(150, 150, Color.BLUE); blueRect.setId("Blue"); blueRect.setOnMousePressed(e -> System.out.println("Mouse Pressed: Blue"/* + e */)); blueRect.setPriorityOrder(1); blueRect.relocate(60, 100); rectsPane.getChildren().addAll(redRect, greenRect, blueRect); final Pane topPane = new Pane(); final HBox rootPane = new HBox(10); final Button removeBtn = new Button(); final Button addBtn = new Button(); addBtn.setText("Add"); addBtn.setOnAction((javafx.event.ActionEvent event) -> { if (!added) { rectsPane.getChildren().add(wheatRect); slider.setDisable(false); removeBtn.setDisable(false); addBtn.setDisable(true); added = true; } }); removeBtn.setText("Remove"); removeBtn.setDisable(true); removeBtn.setOnAction((javafx.event.ActionEvent event) -> { if (added) { rectsPane.getChildren().remove(wheatRect); slider.setDisable(true); removeBtn.setDisable(true); addBtn.setDisable(false); added = false; } }); VBox buttonsPane = new VBox(10); // This set of btns is to prove that priorityOrder has no impact on // layout and focus traversal order. Button btn0 = new Button("Button 0"); btn0.setPriorityOrder(-1); Button btn1 = new Button("Button 1"); btn1.setPriorityOrder(1); Button btn2 = new Button("Button 2"); btn2.setPriorityOrder(0); buttonsPane.getChildren().addAll(addBtn, removeBtn, slider, btn0, btn1, btn2); rootPane.getChildren().addAll(buttonsPane, rectsPane); Scene scene = new Scene(rootPane); rectsPane.setStyle("-fx-border-color: RED;"); stage.setScene(scene); stage.show(); } public static void main(String[] args) throws Exception { launch(args); } }