我想要一些关于如何在用户按下按钮时为窗格实现幻灯片转换的指南,就像Material Design为滑动菜单做的那样.
这是一个视频链接,说明了我的需求.
我尝试过ScaleTransition,TranslateTransition,但他们没有做到这一点.
我试图实现它的方式效率不高.
// swipeMenuPane is builded in SceneBuilder and it is hidden,
// opacity = 0.0 and setX() = -getPrefWidth();
@FXML AnchorPane swipeMenuPane;
@FXML Button menuButton;
menuButton.setOnMouseClicked(e-> {
swipeMenuPane.setOpacity(1.0);
swipeTransition.play()
});
TranslateTransition swipeTransition = new TranslateTransition();
swipeTransition.setNode(swipeMenuPane);
swipeTransition.setDuration(Duration.millis(500));
swipeTransition.setToX(swipeMenuPane.getPrefWidth());
Run Code Online (Sandbox Code Playgroud)
---更新---
这是从这里下载的样本Gluon应用程序.这是一个gradle项目,我修改它以显示一个按钮而不是默认标签.
我想在用户点击按钮时缩小AnchorPane.
我错过了什么?
package com.helloworld;
import com.gluonhq.charm.glisten.animation.ShrinkExpandAnimation;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
ShrinkExpandAnimation anim;
@Override
public void start(Stage stage) { …Run Code Online (Sandbox Code Playgroud) 我想提前道歉,正如前面在“将参数直接从调用者传递给控制器”中讨论的那样,但是我遵循了发现的所有可能的解决方案,但仍然无法使它起作用。
我很难将参数从一个控制器传递到另一个控制器。
特别:
LoginController传递username给MainController。
当我单击登录按钮LoginController时,将其username设置为MainController。但是,加载Main.fxml时username为NULL。
在试图解决这个问题时,我想问一下:
initialize()方法?我想在LoginController调用的时候st.show();?username为NULL,因为我们已经使用Login在LoginController中设置了它的值mainController.setUsername(username)?任何帮助,将不胜感激。
这是我的代码。
LoginController.java
public class LoginController implements Initializable {
...
@FXML TextField username;
@FXML public void actionLoginButton() {
...
Stage st = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("Main.fxml"));
Region root = (Region) loader.load();
Scene scene = new Scene(root);
st.setScene(scene);
MainController …Run Code Online (Sandbox Code Playgroud) javafx ×2