所以我的FXML中有一个BorderPane
,我想要的是重新加载我的BorderPane.Center属性,以便显示不同布局的不同窗格,
我怎样才能做到这一点?以下代码对我不起作用。
p.s:对不起印尼人。
我的FXML:
<BorderPane fx:id="bPane" xmlns:fx="http://javafx.com/fxml" fx:controller="fx.HomeMhsController" stylesheets="@css.css">
<left>
<VBox spacing="10" fx:id="vbox" id="vbox" prefWidth="100" >
<Label id="Label" fx:id="biodata" text="Biodata" onMouseClicked="#showIdentity"/>
<Label id="Label" fx:id="histori" text="Histori Nilai" onMouseClicked="#showHistory" />
<Label id="Label" fx:id="jadwal" text="Jadwal Kuliah" onMouseClicked="#showSchedule" />
<Label id="Label" fx:id="pilih" text="Pilih Mata Kuliah" onMouseClicked="#chooseSchedule"/>
</VBox>
</left>
我的控制器:
public class HomeMhsController{
@FXML private Label biodata2;
@FXML private BorderPane bPane;
@FXML private void showIdentity() throws SQLException{
init.initializeDB();
String query="select * from mahasiswa where nama_dpn ='" + MainController.username + "'";
ResultSet rset = init.stmt.executeQuery(query);
if(rset.next()){
String nim = rset.getString(1);
String nama_dpn = rset.getString(2);
String nama_blkg = rset.getString(3);
String tgl_lahir = rset.getString(4);
String tempat_lahir = rset.getString(5);
String jns_kelamin = rset.getString(6);
String agama = rset.getString(7);
String alamat = rset.getString(8);
String no_hp = rset.getString(9);
biodata2.setText(nim + nama_dpn + nama_blkg + tgl_lahir + tempat_lahir + jns_kelamin + agama + alamat + no_hp);
}
}
@FXML private void showHistory() throws IOException{
FXMLLoader loader = new FXMLLoader();
Parent rootNode = null;
rootNode = loader.load(getClass().getResource("homeMhs_fxml.fxml"));
Label dua = new Label("2");
Pane pane = new Pane();
pane.getChildren().add(dua);
((BorderPane) rootNode).setCenter(pane);
}
@FXML private void showSchedule() throws SQLException, IOException{
FXMLLoader loader = new FXMLLoader();
Parent rootNode = null;
rootNode = loader.load(getClass().getResource("homeMhs_fxml.fxml"));
Label tiga = new Label("3");
Pane pane = new Pane();
pane.getChildren().add(tiga);
((BorderPane) rootNode).setCenter(pane);
}
@FXML private void chooseSchedule() throws SQLException{
}
答案 0 :(得分:0)
在以下代码段中:
@FXML private void showHistory() throws IOException{
FXMLLoader loader = new FXMLLoader();
Parent rootNode = null;
rootNode = loader.load(getClass().getResource("homeMhs_fxml.fxml"));
Label dua = new Label("2");
Pane pane = new Pane();
pane.getChildren().add(dua);
((BorderPane) rootNode).setCenter(pane);
}
您正在再次加载fxml文件,这是一个新实例,与您已有的实例不同(因为此控制器类中的此方法)。此外,您没有对此新加载的任何内容执行任何操作(即rootNode
未添加到任何场景中)。
而只是使用现有的注入边框窗格:
@FXML private void showHistory() {
Label dua = new Label("2");
Pane pane = new Pane();
pane.getChildren().add(dua);
bPane.setCenter(pane);
}
或更短:
@FXML private void showHistory() {
bPane.setCenter(new Pane(new Label("2")));
}