2017-05-02 18 views
0

しばらくの間、「メニュー画面」が表示されます。JavaFXボタンonActionは、選択したFXMLビューを開きません。

私がアクティブ顧客PANELをクリックしたとき、それは文句を言わないCustomerDisplay.fxmlを開く

以下

Main Screen

は私のコードです。

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を印刷し

public class SimulatorController implements Initializable{{ 
. 
. 
. 
    @FXML 
    public void clickCustomer (ActionEvent event) throws IOException{ 
     log.info("Starting Customer Panel"); 
     MainApp.getInstance().openCustomerPanel()**; 
    } 
} 

( "カスタマー・パネルの起動")が、私はどんな新しいウィンドウを見ることができませんでした。 メイン画面のボタンをクリックして新しいウィンドウを表示する方法を知りたい。メイン画面は閉じない限り開いたままです。私たちは新しいステージを定義する必要がありますか?

+0

あなたのメソッド 'openXXXPanel'がちょうどFXMLファイルをロードし、変数' content'へのルート要素に対応するオブジェクトを割り当てるが、彼らは新しいコンテンツで何もしない:ここでは は、作業コードです。現在のシーンのルートを 'content'(既存のウィンドウを使いたい場合)に設定するか、新しいステージを作成する(新しいウィンドウが必要な場合)必要があります。 –

+0

セカンダリステージを作成しますが、クリックするとメイン画面にポップアップメイン画面が表示されます。 –

+0

これでOKです。あなたの洞察に感謝します –

答えて

0

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(); 
     } 
    } 
関連する問題