关于场景/锚定窗格

时间:2019-06-15 23:59:37

标签: java javafx

我创建了带有按钮的菜单 如何通过单击此按钮来调用场景或锚定窗格,然后在当前窗口中打开而不打开另一个窗口

如果有人可以给我一个如何做到这一点的例子 以及它是在调用新场景还是锚定面板

我已经看了很多东西,却一无所获

我的代码控制项:

package Controller;

import Views.Menu;
import com.jfoenix.controls.JFXButton;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;


public class MenuC implements Initializable {


    @FXML
    private JFXButton cadastrar;

    @FXML
    private JFXButton listagemUser;

    @FXML
    private JFXButton historicoRequi;

    @FXML
    private JFXButton addReq;

    @FXML
    private JFXButton setting;

    @FXML
    private JFXButton logout;
    @FXML
    void close(ActionEvent event) {
        Menu.getStage().close();
    }
    public void fecha(){
        Menu.getStage().close();
    }
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }    

}

我的主要班级

public class Menu extends Application {
    private static Stage stage; //uma janela
    private double x, y;

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("Menu.fxml")); //carrega fxml

        Scene scene = new Scene(root); //coloca o fxml em uma cena
        stage.setScene(scene); // coloca a cena em uma janela
        //abre a janela
        setStage(stage);
        //set stage borderless
        stage.initStyle(StageStyle.UNDECORATED);

        //drag it here
        root.setOnMousePressed(event -> {
            x = event.getSceneX();
            y = event.getSceneY();
        });
        root.setOnMouseDragged(event -> {

            stage.setX(event.getScreenX() - x);
            stage.setY(event.getScreenY() - y);

        });
        stage.show();
    }


    public static Stage getStage(){
        return stage;
    }

    public static void setStage(Stage stage){
        Menu.stage = stage;
    }

    public static void main(String[] args) {
        launch(args);
    }
}

0 个答案:

没有答案