Example usage for javafx.scene.shape Circle toFront

List of usage examples for javafx.scene.shape Circle toFront

Introduction

In this page you can find the example usage for javafx.scene.shape Circle toFront.

Prototype

public void toFront() 

Source Link

Document

Moves this Node to the front of its sibling nodes in terms of z-order.

Usage

From source file:Main.java

private Circle createCircle(double x, double y, double r, Color color) {
    Circle circle = new Circle(x, y, r, color);

    circle.setCursor(Cursor.HAND);

    circle.setOnMousePressed((t) -> {
        orgSceneX = t.getSceneX();/*w  w w  . j  av a 2 s  .c o  m*/
        orgSceneY = t.getSceneY();

        Circle c = (Circle) (t.getSource());
        c.toFront();
    });
    circle.setOnMouseDragged((t) -> {
        double offsetX = t.getSceneX() - orgSceneX;
        double offsetY = t.getSceneY() - orgSceneY;

        Circle c = (Circle) (t.getSource());

        c.setCenterX(c.getCenterX() + offsetX);
        c.setCenterY(c.getCenterY() + offsetY);

        orgSceneX = t.getSceneX();
        orgSceneY = t.getSceneY();
    });
    return circle;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 500, 260);

    // circles//w w w  .j  av a  2  s. co  m
    Circle redCircle = createCircle(100, 50, 30, Color.RED);
    Circle blueCircle = createCircle(20, 150, 20, Color.BLUE);
    Circle greenCircle = createCircle(40, 100, 40, Color.GREEN);

    Line line1 = connect(redCircle, blueCircle);
    Line line2 = connect(redCircle, greenCircle);
    Line line3 = connect(greenCircle, blueCircle);

    // add the circles
    root.getChildren().add(redCircle);
    root.getChildren().add(blueCircle);
    root.getChildren().add(greenCircle);

    // add the lines
    root.getChildren().add(line1);
    root.getChildren().add(line2);
    root.getChildren().add(line3);

    // bring the circles to the front of the lines
    redCircle.toFront();
    blueCircle.toFront();
    greenCircle.toFront();

    primaryStage.setScene(scene);
    primaryStage.show();
}