移动按钮或javafx中的任何其他东西?

时间:2016-08-28 14:07:11

标签: javafx

    Button btn=new Button("Click Me");
    Button btn2=new Button("Click");
    btn2.setOnAction(e->System.exit(0));
    btn.setOnAction(new EventHandler<ActionEvent>(){


        public void handle(ActionEvent action){
            System.out.println(5);
        }
    });
    btn2.relocate(0, 0);
    StackPane root=new StackPane();
    root.getChildren().add(btn);
    root.getChildren().add(btn2);
    Scene sene=new Scene(root,500,265);
    primaryStage.setScene(sene);
    primaryStage.show();

我想移动按钮并使用上面的代码,但我无法移动按钮? 代码中的问题是什么?是他们的任何其他方法吗?

1 个答案:

答案 0 :(得分:0)

答案是:

http://docs.oracle.com/javafx/2/animations/jfxpub-animations.htm

JavaFX已准备好动画库。

  

一个例子(矩形将褪色):

final Rectangle rect1 = new Rectangle(10, 10, 100, 100);
rect1.setArcHeight(20);
rect1.setArcWidth(20);
rect1.setFill(Color.RED);

...

FadeTransition ft = new FadeTransition(Duration.millis(3000), rect1);
ft.setFromValue(1.0); ft.setToValue(0.1);
ft.setCycleCount(Timeline.INDEFINITE);
ft.setAutoReverse(true);
ft.play();

在您的代码中,您可能需要TranslateTranstition或仅使用translateXtranslateY方法