JavaFX按钮onAction赢得';t打开选定的FXML视图

JavaFX按钮onAction赢得';t打开选定的FXML视图,javafx,controller,Javafx,Controller,我被“菜单屏幕”卡住了一段时间 当我单击激活的客户面板时,它不会打开CustomerDisplay.fxml 下面是我的代码 public class MainApp extends Application { protected Parent content; private Stage primaryStage; private Stage secondStage; private CustomerController custCtrl; private MaintainerContro

我被“菜单屏幕”卡住了一段时间

当我单击激活的客户面板时,它不会打开CustomerDisplay.fxml

下面是我的代码

public class MainApp extends Application {

protected Parent content;
private Stage primaryStage;
private Stage secondStage;
private CustomerController custCtrl;
private MaintainerController mntnCtrl;
private MachineryController machCtrl;
private String fxml="";
public static MainApp instance;

public MainApp () {
    instance=this;
}

/**
 * @param args
 */
public static void main(String[] args) {    
    launch(args);
}

public static MainApp getInstance() {
    return instance;
}

@Override
public void start(Stage primaryStage) throws Exception {
    initializePanel();
    Scene scene = new Scene(content);

    primaryStage.setResizable(false);
    primaryStage.initStyle(StageStyle.UTILITY);

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

private void initializePanel() throws IOException{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("fxml/SimulatorDisplay.fxml"));
    content = loader.load();        
}

public void openCustomerPanel() throws IOException{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("fxml/CustomerDisplay.fxml"));
    content = loader.load(); 
}

public void openMaintainerPanel() throws IOException{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("fxml/MaintainerDisplay.fxml"));
    content = loader.load();        
}

public void openMachineryPanel() throws IOException{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource("fxml/MachineryDisplay.fxml"));
    content = loader.load();        
}   
}

它打印log.info(“启动客户面板”),但我看不到任何新窗口。
我想知道我们如何单击主屏幕上的按钮,并显示新窗口。除非我们关闭主屏幕,否则它将保持打开状态。我们需要定义新的阶段吗

基于James_D的评论; 以下是工作代码:

        public class MainApp extends Application {

        public static MainApp instance;
        private Stage secondaryStage;
    .
    .
    .

        public void openCustomerPanel() throws IOException{
            FXMLLoader loader = new FXMLLoader();
            secondaryStage= new Stage();
            loader.setLocation(getClass().getResource("fxml/CustomerDisplay.fxml"));
            content = loader.load(); 
            Scene scene = new Scene(content);
            secondaryStage.setScene(scene);
            secondaryStage.show();
        }
    }

您的方法
openXXXPanel
只需加载一个FXML文件,并将根元素对应的对象分配给变量
content
,但它们不处理新内容。您需要将当前场景的根设置为
content
(如果您想使用现有窗口),或者创建一个新的
阶段
(如果您想创建一个新窗口)。我创建了第二阶段,但当单击确定时,它会将弹出的主屏幕保持在主屏幕上方,现在我得到了它。谢谢你的洞察力
        public class MainApp extends Application {

        public static MainApp instance;
        private Stage secondaryStage;
    .
    .
    .

        public void openCustomerPanel() throws IOException{
            FXMLLoader loader = new FXMLLoader();
            secondaryStage= new Stage();
            loader.setLocation(getClass().getResource("fxml/CustomerDisplay.fxml"));
            content = loader.load(); 
            Scene scene = new Scene(content);
            secondaryStage.setScene(scene);
            secondaryStage.show();
        }
    }