Example usage for javafx.scene Scene getWidth

List of usage examples for javafx.scene Scene getWidth

Introduction

In this page you can find the example usage for javafx.scene Scene getWidth.

Prototype

public final double getWidth() 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Text msg = new Text("java2s.com");
    msg.setTextOrigin(VPos.TOP);//from  w ww .jav a 2 s. c o m
    msg.setFont(Font.font(24));

    Pane root = new Pane(msg);
    root.setPrefSize(500, 70);
    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.setTitle("Scrolling Text");
    stage.show();

    double sceneWidth = scene.getWidth();
    double msgWidth = msg.getLayoutBounds().getWidth();

    KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth);
    KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);

    KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0 * msgWidth);
    KeyFrame endFrame = new KeyFrame(Duration.seconds(3), endKeyValue);

    Timeline timeline = new Timeline(initFrame, endFrame);

    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
}

From source file:Main.java

public void setCamOffset(final Cam camOffset, final Scene scene) {
    double width = scene.getWidth();
    double height = scene.getHeight();
    camOffset.t.setX(width / 2.0);/*  ww  w  .j  a  va  2 s .  c om*/
    camOffset.t.setY(height / 2.0);
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 800, 600, Color.BLACK);
    primaryStage.setScene(scene);//w  ww . ja v a 2 s  .c o m
    Group circles = new Group();
    for (int i = 0; i < 30; i++) {
        Circle circle = new Circle(150, Color.web("white", 0.05));
        circle.setStrokeType(StrokeType.OUTSIDE);
        circle.setStroke(Color.web("white", 0.16));
        circle.setStrokeWidth(4);
        circles.getChildren().add(circle);
    }
    Rectangle colors = new Rectangle(scene.getWidth(), scene.getHeight(),
            new LinearGradient(0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE,
                    new Stop[] { new Stop(0, Color.web("#f8bd55")), new Stop(0.14, Color.web("#c0fe56")),
                            new Stop(0.28, Color.web("#5dfbc1")), new Stop(0.43, Color.web("#64c2f8")),
                            new Stop(0.57, Color.web("#be4af7")), new Stop(0.71, Color.web("#ed5fc2")),
                            new Stop(0.85, Color.web("#ef504c")), new Stop(1, Color.web("#f2660f")), }));
    Group blendModeGroup = new Group(
            new Group(new Rectangle(scene.getWidth(), scene.getHeight(), Color.BLACK), circles), colors);
    colors.setBlendMode(BlendMode.OVERLAY);
    root.getChildren().add(blendModeGroup);
    circles.setEffect(new BoxBlur(10, 10, 3));
    Timeline timeline = new Timeline();
    for (Node circle : circles.getChildren()) {
        timeline.getKeyFrames().addAll(new KeyFrame(Duration.ZERO, // set start position at 0
                new KeyValue(circle.translateXProperty(), random() * 800),
                new KeyValue(circle.translateYProperty(), random() * 600)),
                new KeyFrame(new Duration(40000), // set end position at 40s
                        new KeyValue(circle.translateXProperty(), random() * 800),
                        new KeyValue(circle.translateYProperty(), random() * 600)));
    }
    // play 40s of animation
    timeline.play();

    primaryStage.show();
}

From source file:Main.java

public void setCamScale(final Cam cam, final Scene scene) {
    final Bounds bounds = cam.getBoundsInLocal();
    final double pivotX = bounds.getMinX() + bounds.getWidth() / 2;
    final double pivotY = bounds.getMinY() + bounds.getHeight() / 2;
    final double pivotZ = bounds.getMinZ() + bounds.getDepth() / 2;

    double width = scene.getWidth();
    double height = scene.getHeight();

    double scaleFactor = 1.0;
    double scaleFactorY = 1.0;
    double scaleFactorX = 1.0;
    if (bounds.getWidth() > 0.0001) {
        scaleFactorX = width / bounds.getWidth(); // / 2.0;
    }/*from w  w w . j  a  va 2s  .com*/
    if (bounds.getHeight() > 0.0001) {
        scaleFactorY = height / bounds.getHeight(); //  / 1.5;
    }
    if (scaleFactorX > scaleFactorY) {
        scaleFactor = scaleFactorY;
    } else {
        scaleFactor = scaleFactorX;
    }
    cam.s.setX(scaleFactor);
    cam.s.setY(scaleFactor);
    cam.s.setZ(scaleFactor);
}

From source file:Main.java

private void addBouncyBall(final Scene scene) {
    final Circle ball = new Circle(100, 100, 20);

    final Group root = (Group) scene.getRoot();
    root.getChildren().add(ball);/*from   ww w .  j a v a2 s  . com*/

    Timeline tl = new Timeline();
    tl.setCycleCount(Animation.INDEFINITE);
    KeyFrame moveBall = new KeyFrame(Duration.seconds(.0200), new EventHandler<ActionEvent>() {

        public void handle(ActionEvent event) {

            double xMin = ball.getBoundsInParent().getMinX();
            double yMin = ball.getBoundsInParent().getMinY();
            double xMax = ball.getBoundsInParent().getMaxX();
            double yMax = ball.getBoundsInParent().getMaxY();

            if (xMin < 0 || xMax > scene.getWidth()) {
                dx = dx * -1;
            }
            if (yMin < 0 || yMax > scene.getHeight()) {
                dy = dy * -1;
            }

            ball.setTranslateX(ball.getTranslateX() + dx);
            ball.setTranslateY(ball.getTranslateY() + dy);

        }
    });

    tl.getKeyFrames().add(moveBall);
    tl.play();
}