2017-02-11 6 views
-1

Java FXアプリケーションで非モーダルおよびモーダルダイアログを処理する方法が必要です。JavaFX 8非モーダルおよびモーダルダイアログを処理するメソッド

プライマリとダイアログの段階が妥当でなければ、JavaFXは動作不能になります。

すべてのモーダルダイアログでは、ユーザーが入力した内容を受け入れる前に検証が必要です。
DRYを有効にする必要があります。

モノリシックなスパゲッティコードを避けるには、SceneBuilderも有効である必要があります。

私はインターネットを精査しましたが、そのようなJavaFXメソッドは見つかりませんでした。

このようなJavaFXメソッドを作成するには、どのような考慮事項が必要ですか?

結果コードにはどのようなものが含まれますか?

どのようにしてそのようなメソッドを呼び出して利用するのですか?

答えて

0

以下のコメント欄の回答があります。

/** 
    * @author Arch Brooks, CEO Brooks Computing Systems, LLC authored this 
    *   method.<br> 
    * 
    * @since February 8, 2017<br> 
    * 
    * @param panel 
    *   The fxml document to serve as the dialog. 
    * @param css 
    *   The cascading style sheet used by the dialog. 
    * @param caption 
    *   The dialog caption or title. 
    * @param moDal 
    *   Identifies modality true = modal otherwise non modal. <br> 
    *   <br> 
    *   This method should be placed in the primary java class. <br> 
    *   <br> 
    *   Place the following calling sequence in the start constructor 
    *   of the FX application. <br> 
    *   <br> 
    *   ShowTopFormDlg("Your.fxml", "Your.css", "Your Title", false); 
    *   <br> 
    *   <br> 
    *   Place the following calling sequence in the controller when a 
    *   modal dialog is desired. <br> 
    *   <br> 
    *   ShowTopFormDlg("Your.fxml", "Your.css", "Your Title", true); 
    *   <br> 
    *   <br> 
    *   Globals in the JavaFX class housing the start constructor are 
    *   as follows: <br> 
    *   <br> 
    *   public static FXMLLoader loader;<br> 
    *   public static Stage dialogStage;<br> 
    *   public static BorderPane page;<br> 
    *   private static BorderPane mainLayout;<br> 
    *   public static Scene scene;<br> 
    *   public static Stage dialogStage;<br> 
    *   public static Stage primaryStage;<br> 
    *   <br> 
    *   <br> 
    *   In any controller using this calling sequence the following 
    *   import is required. <br> 
    *   <br> 
    *   import com.bcs.FXDlgTest2.*; 
    */ 

    public static void ShowTopFormDlg(String panel, String css, String caption, Boolean moDal) { 
     loader = new FXMLLoader(); 
     loader.setLocation(TopForm_so.class.getResource(panel)); 
     if (moDal) { 
      dialogStage = new Stage(); 
      try { 
       page = loader.load(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } else { 
      try { 
       mainLayout = loader.load(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
     if (moDal) { 
      scene = new Scene(page); 
     } else { 
      scene = new Scene(mainLayout); 
     } 
     scene.getStylesheets().add((TopForm_so.class.getResource(css).toExternalForm())); 
     if (moDal) { 
      dialogStage.setScene(scene); 
      dialogStage.setTitle(caption); 
      dialogStage.initModality(Modality.WINDOW_MODAL); 
      dialogStage.showAndWait(); 
     } else { 
      primaryStage.setScene(scene); 
      primaryStage.setTitle(caption); 
      primaryStage.show(); 
     } 
    } 
関連する問題