コンテナの上部に BorderPane を含む GUI を設計したい コンテナの左側には、さまざまな FXML ファイルのコンテナの中央のコンテンツを変更するさまざまなボタンを持つアコーディオンがあります。 Spotify のデスクトップ アプリ
私は動作するプロトタイプを手に入れました、そしてそれはこのように見えます
FXML の変更が発生し、buttos が非常にうまく応答します。私が抱えている問題は、BoderPane の中央部分を埋める FXML が自動化されず、FXML の大きな部分にある場合は表示されず、FXML が中央部分に残されたスペースが同じ小さなサイズのままで、何もないスペースがたくさん残っているよりも小さい
これは、新しい FXML を呼び出すための私のコードです
public void lanzaUno(){
try {
// load first FXML
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Coordinador.class.getResource(
"VistaControlador/Usuario/Uno.fxml"));
/*i put the AnchorPane inside of a
ScrollPane for the desire funcionality of alot
of vertical space for many nodes in a single FXML file
*/
ScrollPane unoAnchorPane = (ScrollPane) loader.load();
UnoController controller = loader.getController();
//example method for passing variables to the FXML controler
controller.pasoPrincipal(this, primaryStage, "Rhutt");
//puts the FXML in the center of the BorderPane
rootLayout.setCenter(unoAnchorPane);
//this if for trying to accommodate the content en the BorderPane
BorderPane.setAlignment(unoAnchorPane, Pos.TOP_LEFT);
} catch (IOException e) {
e.printStackTrace();
}
}
私の最初の質問は、BorderPane で利用可能なスペースを占有するこのコンテンツの FXML の呼び出しに欠けているものは何ですか?
私の2番目の質問は、FXMLの変更に関するものです.BorderPaneの変更を別のものに渡すと、BorderPaneの変更が瞬時に行われ、非常に悪いように見えます中央の FXML のコンテンツ?、移行を少し改善するだけで、あまり詳しく説明する必要はありません。
編集
すべてのFXMLのパラメーターを送受信し、新しいFXMLを呼び出すメソッドを宣言するコーディネータークラスを取得したので、コーディネータークラス、コントローラーを持つFXMLルート、および2つのFXMLとそれぞれに異なるものを持つコントローラーがあります1 つ、この 2 つの FXML は、ルートの BorderPane 中央で変更されるものです。
これはコーディネータークラスです
//Variables
private Stage primaryStage;
private BorderPane rootLayout;
/**
* launh
* @param primaryStage
*
*/
@Override
public void start(Stage primaryStage) throws Exception{
// Inicializa la escena
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Login");
this.primaryStage.centerOnScreen();
//star method
iniLogin();
}
/**
*load the root scene
*/
public void iniLogin(){
try {
// Carga el loader.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(com.aohys.rehabSys.MVC.Coordinador.class.getResource(
"VistaControlador/Pricipal/Principal.fxml"));
rootLayout = (BorderPane) loader.load();
//the root scene
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
// Da acceso al programa principal.
PrincipalController controller = loader.getController();
controller.pasoPrincipal(this, primaryStage);
primaryStage.centerOnScreen();
// Muesta la escena,
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
このメソッドの後に、2 つの変化する FXML 呼び出し LanzaUno、LanzaDos を呼び出す最初のメソッドのような 2 つの同一のメソッドがあります。
これは私のルードFXMLコントローラーです
public class PrincipalController implements Initializable {
//variable of the coordinator class
private Coordinador cordi;
private Stage stage;
/**
* method for passing parameters to the FXML
* @param cordi
* @param stage
*/
public void pasoPrincipal(Coordinador cordi, Stage stage) {
this.cordi = cordi;
this.stage = stage;
}
//FXML in root
@FXML private Button btt1;
@FXML private Button btt2;
@FXML public static StackPane stackPane;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
//Call the firts FXML
btt1.setOnAction((evento)->{
cordi.lanzaUno();
});
//Call the second FXML
btt2.setOnAction((evento)->{
cordi.lanzaDos();
});
}
現時点では、2 つの FXML のコントローラーは何もしません。