我正在创建窗口应用程序,其中base作为边框窗格。我在类中定义了这个边框窗格。在边框窗格的中心,我已经放置了锚窗格。此锚点窗格在另一个类控制器中定义。在锚点窗格中,当我单击按钮时,我想将边框窗格的中心更改为另一个场景。我怎么能让它成为可能?
dashboard.fxml it contains the border pane in center odf the border pane i have loaded the homepage.fxml when I press the item button on the dashboard I want to change the center alone like this i.e itempage.fxml
dashboardcontroller.java
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.ResourceBundle;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXTreeView;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.control.TreeItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class dashboardcontroller implements Initializable {
@FXML
private JFXButton logout;
@FXML
public BorderPane basepan;
@FXML
private JFXTreeView<String> menu;
@FXML
private Label time;
@FXML
private Label date;
static AnchorPane fxmlLoader;
ImageView homeicon = new ImageView(new Image(getClass().getResourceAsStream("/images/if_home_126572.png"), 20,20 , true,true));
ImageView itemicon = new ImageView(new Image(getClass().getResourceAsStream("/images/if_Menu_List_Text_Line_Item_Bullet_Paragraph_1654364.png"), 20,20 , true,true));
ImageView locationicon = new ImageView(new Image(getClass().getResourceAsStream("/images/locationpin.png"), 20,20 , true,true));
ImageView salesandpurchaseicon = new ImageView(new Image(getClass().getResourceAsStream("/images/if_analytics_1954530.png"), 20,20 , true,true));
ImageView reporticon = new ImageView(new Image(getClass().getResourceAsStream("/images/if_icon-45-note-list_315263.png"), 20,20 , true,true));
ImageView usersicon = new ImageView(new Image(getClass().getResourceAsStream("/images/if_users_2561497.png"), 20,25 , true,true));
ImageView addnewitem = new ImageView(new Image(getClass().getResourceAsStream("/images/addnew.png"),20,20,true,true));
public void clock()
{
Thread clock = new Thread()
{
public void run()
{
try {
while(true)
{
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMM dd, yyyy");
SimpleDateFormat stf = new SimpleDateFormat("hh:mm:ss a");
Calendar calendar = new GregorianCalendar();
Platform.runLater(new Runnable()
{
@Override
public void run() {
time.setText(stf.format(calendar.getTime()));
date.setText(sdf.format(calendar.getTime()));
}
});
sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
clock.start();
}
public void getmenu(MouseEvent event)
{
TreeItem<String> item = menu.getSelectionModel().getSelectedItem();
if(item.getValue().equals("Items Master"))
{
Thread itemthread = new Thread() {
public void run()
{
Platform.runLater(new Runnable()
{
@Override
public void run() {
try {
fxmlLoader = FXMLLoader.load(dashboardcontroller.class.getResource("itempage.fxml"));
}catch(Exception e)
{
e.printStackTrace();
}
fxmlLoader.setMaxHeight(10000);
fxmlLoader.setMaxWidth(10000);
basepan.setCenter(fxmlLoader);
}
});
}
};
itemthread.start();
}else if(item.getValue().equals("Home"))
{
Thread homethread = new Thread()
{
public void run()
{
Platform.runLater(new Runnable()
{
@Override
public void run() {
try {
fxmlLoader = FXMLLoader.load(dashboardcontroller.class.getResource("homepage.fxml"));
}catch(Exception e)
{
e.printStackTrace();
}
fxmlLoader.setMaxHeight(10000);
fxmlLoader.setMaxWidth(10000);
basepan.setCenter(fxmlLoader);
}
});
}
};
homethread.start();
}
}
@FXML
public void itempress()
{
try {
fxmlLoader = FXMLLoader.load(dashboardcontroller.class.getResource("itempage.fxml"));
}catch(Exception e)
{
e.printStackTrace();
}
fxmlLoader.setMaxHeight(10000);
fxmlLoader.setMaxWidth(10000);
basepan.setCenter(fxmlLoader);
}
@FXML
public void logout(ActionEvent event)
{
final Node source = (Node) event.getSource();
final Stage stage =(Stage) source.getScene().getWindow();
stage.close();
main.getPrimaryStage().show();
}
@FXML
public void homepress(ActionEvent event)
{
try {
fxmlLoader = FXMLLoader.load(getClass().getResource("homepage.fxml"));
} catch (Exception e) {
e.printStackTrace();
}
fxmlLoader.setMaxHeight(10000);
fxmlLoader.setMaxWidth(10000);
basepan.setCenter(fxmlLoader);
//System.out.println("home pressed");
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
final Tooltip tooltiplogout = new Tooltip();
tooltiplogout.setText("Logout");
tooltiplogout.setFont(Font.font("SanSerif",13));
Tooltip.install(logout, tooltiplogout);
TreeItem<String> root = new TreeItem<>("Root");
TreeItem<String> home = new TreeItem<>("Home", homeicon);
TreeItem<String> item = new TreeItem<>("Items Master", itemicon);
TreeItem<String> addnew = new TreeItem<>("Add New" , addnewitem);
TreeItem<String> location = new TreeItem<>("Location Master", locationicon);
TreeItem<String> salesandpurchase = new TreeItem<>("Sales and Purchase Master", salesandpurchaseicon);
TreeItem<String> report = new TreeItem<>("Report Master", reporticon);
TreeItem<String> users = new TreeItem<>("Users Master", usersicon);
root.getChildren().add(home);
root.getChildren().add(item);
root.getChildren().add(location);
root.getChildren().add(salesandpurchase);
root.getChildren().add(report);
root.getChildren().add(users);
item.getChildren().add(addnew);
menu.setRoot(root);
menu.setShowRoot(false);
menu.getStyleClass().add("myTree");
clock();
try {
fxmlLoader = FXMLLoader.load(getClass().getResource("homepage.fxml"));
} catch (Exception e) {
System.out.println("dashboard error");
e.printStackTrace();
}
fxmlLoader.setMaxHeight(10000);
fxmlLoader.setMaxWidth(10000);
basepan.setCenter(fxmlLoader);
}
public void itemscreenchange()
{
Thread itemthread = new Thread()
{
public void run()
{
Platform.runLater(new Runnable()
{
@Override
public void run() {
try {
fxmlLoader = FXMLLoader.load(dashboardcontroller.class.getResource("itempage.fxml"));
}catch(Exception e)
{
e.printStackTrace();
}
fxmlLoader.setMaxHeight(10000);
fxmlLoader.setMaxWidth(10000);
basepan.setCenter(fxmlLoader);
}
});
}
};
itemthread.start();
}
}
homepagecontroller.java
import java.io.IOException;
import java.net.URL;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ResourceBundle;
import com.jfoenix.controls.JFXButton;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.TilePane;
import javafx.stage.Stage;
public class homepagecontroller implements Initializable {
@FXML
private AnchorPane pane;
@FXML
private static HBox hbox1;
@FXML
private StackPane stcpane1;
@FXML
private StackPane stkpane2;
@FXML
private HBox hbox2;
@FXML
private JFXButton item;
@FXML
private JFXButton sales_and_purchase;
@FXML
private JFXButton location_master;
@FXML
private JFXButton report_master;
@FXML
private JFXButton users_manager;
@FXML
public TilePane tilpane;
@FXML
public LineChart<String,Double> graph;
@FXML
private CategoryAxis x;
@FXML
private NumberAxis y;
AnchorPane fxmlLoader;
@Override
public void initialize(URL url, ResourceBundle arg1) {
pane.widthProperty().addListener(new ChangeListener<Number>()
{
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue,Number newValue) {
}
});
XYChart.Series<String,Double> series = new XYChart.Series<>();
XYChart.Series<String, Double> series2 = new XYChart.Series<>();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/gdlashmi?useSSL=false","root","");
PreparedStatement pst = (PreparedStatement) con.prepareStatement("SELECT MonthName(`soldoutdate`.`sold date`) AS Date ,SUM(gross_weight) as `Total Weight` FROM soldoutdate JOIN stocklist WHERE soldoutdate.id = stocklist.id and Year(`sold date`) = Year(CURRENT_DATE) AND (stocklist.Purity = \"Regular\" OR stocklist.Purity = \"KDM\") GROUP BY Month(`soldoutdate`.`sold date`)");
PreparedStatement pst1 = (PreparedStatement) con.prepareStatement("SELECT MonthName(`soldoutdate`.`sold date`) AS Date ,SUM(`stocklist`.`gross_weight`) as `Total Weight` FROM soldoutdate JOIN stocklist WHERE soldoutdate.id = stocklist.id and Year(`sold date`) = Year(CURRENT_DATE) AND (stocklist.Purity = \"92M-Silver\" OR stocklist.Purity = \"Silver\") GROUP BY Month(`soldoutdate`.`sold date`)");
ResultSet rs = pst.executeQuery();
ResultSet rs1 = pst1.executeQuery();
while(rs.next())
{
series.getData().add(new XYChart.Data<>(rs.getString(1),Double.valueOf(rs.getDouble(2))));
series.setName("Gold");
}
while(rs1.next())
{
//series2.getData().add(new XYChart.Data<>(rs1.getString(1),Integer.valueOf(rs1.getInt(2))));
series2.getData().add(new XYChart.Data<>(rs1.getString(1),Double.valueOf(rs1.getDouble(2))));
series2.setName("Silver");
}
} catch (Exception e) {
e.printStackTrace();
}
graph.getData().add(series);
graph.getData().add(series2);
}
public void repostiongraph()
{
graph.setLayoutY(tilpane.getPrefHeight()+10);
}
public void itempress(ActionEvent event) throws IOException
{
//this is the place i want to load the itempage.fxml in the border pane of dashboardcontroller.java
}
}
itempagecontroller.java
import java.net.URL;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.ResourceBundle;
import java.util.function.Predicate;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXComboBox;
import com.jfoenix.controls.JFXTextField;
import com.jfoenix.controls.JFXTreeTableColumn;
import com.jfoenix.controls.JFXTreeTableView;
import com.jfoenix.controls.RecursiveTreeItem;
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import application.itempagecontroller.item;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableColumn.CellDataFeatures;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.util.Callback;
public class itempagecontroller implements Initializable{
@FXML
private AnchorPane itempane;
@FXML
private JFXTreeTableView<item> itemlist;
@FXML
private JFXTextField searchtext;
@FXML
private JFXButton searchbtn;
@FXML
private HBox hbox;
@FXML
private JFXComboBox<String> columncombo;
class item extends RecursiveTreeObject<item>{
StringProperty itemname;
StringProperty id;
StringProperty purity;
StringProperty location;
StringProperty weight;
StringProperty createdon;
StringProperty itemstatus;
public item(String itemname,String id,String purity,String location,String weight,String createdon,String itemstatus)
{
this.itemname = new SimpleStringProperty(itemname);
this.id = new SimpleStringProperty(id);
this.purity = new SimpleStringProperty(purity);
this.location = new SimpleStringProperty(location);
this.weight = new SimpleStringProperty(weight);
this.createdon = new SimpleStringProperty(createdon);
this.itemstatus = new SimpleStringProperty(itemstatus);
}
}
@FXML
void searchkeypress(KeyEvent event) {
if(event.getCode().equals(KeyCode.ENTER))
{
itemlist.setPredicate(new Predicate<TreeItem<item>>()
{
@Override
public boolean test(TreeItem<item> cont) {
String selected = columncombo.getValue().toString();
Boolean flag = null;
if(selected == "All")
{
flag = cont.getValue().id.getValue().contains(searchtext.getText()) || cont.getValue().itemname.getValue().contains(searchtext.getText()) || cont.getValue().purity.getValue().contains(searchtext.getText()) || cont.getValue().location.getValue().contains(searchtext.getText()) || cont.getValue().weight.getValue().contains(searchtext.getText()) || cont.getValue().createdon.getValue().contains(searchtext.getText()) || cont.getValue().itemstatus.getValue().contains(searchtext.getText());
}else if(selected == "ID")
{
flag = cont.getValue().id.getValue().contains(searchtext.getText());
}else if(selected == "Item Name")
{
flag = cont.getValue().itemname.getValue().contains(searchtext.getText());
}else if(selected == "Purity")
{
flag = cont.getValue().purity.getValue().contains(searchtext.getText());
}else if(selected == "Location")
{
flag = cont.getValue().location.getValue().contains(searchtext.getText());
}else if(selected == "Gross weight")
{
flag = cont.getValue().weight.getValue().contains(searchtext.getText());
}else if(selected == "Created On")
{
flag = cont.getValue().createdon.getValue().contains(searchtext.getText());
}else if(selected == "Item Status")
{
flag = cont.getValue().itemstatus.getValue().contains(searchtext.getText());
}
return flag;
}
});
}else if(event.getCode().equals(KeyCode.BACK_SPACE))
{
if(searchtext.getText().toString().length() == 1)
{
itemlist.setPredicate(new Predicate<TreeItem<item>>()
{
@Override
public boolean test(TreeItem<item> cont) {
String selected = columncombo.getValue().toString();
Boolean flag = null;
if(selected == "All")
{
flag = cont.getValue().id.getValue().contains(searchtext.getText()) || cont.getValue().itemname.getValue().contains(searchtext.getText()) || cont.getValue().purity.getValue().contains(searchtext.getText()) || cont.getValue().location.getValue().contains(searchtext.getText()) || cont.getValue().weight.getValue().contains(searchtext.getText()) || cont.getValue().createdon.getValue().contains(searchtext.getText()) || cont.getValue().itemstatus.getValue().contains(searchtext.getText());
}else if(selected == "ID")
{
flag = cont.getValue().id.getValue().contains(searchtext.getText());
}else if(selected == "Item Name")
{
flag = cont.getValue().itemname.getValue().contains(searchtext.getText());
}else if(selected == "Purity")
{
flag = cont.getValue().purity.getValue().contains(searchtext.getText());
}else if(selected == "Location")
{
flag = cont.getValue().location.getValue().contains(searchtext.getText());
}else if(selected == "Gross weight")
{
flag = cont.getValue().weight.getValue().contains(searchtext.getText());
}else if(selected == "Created On")
{
flag = cont.getValue().createdon.getValue().contains(searchtext.getText());
}else if(selected == "Item Status")
{
flag = cont.getValue().itemstatus.getValue().contains(searchtext.getText());
}
return flag;
}
});
}
}
}
@FXML
public void searchpress(ActionEvent event)
{
itemlist.setPredicate(new Predicate<TreeItem<item>>()
{
@Override
public boolean test(TreeItem<item> cont) {
String selected = columncombo.getValue().toString();
Boolean flag = null;
if(selected == "All")
{
flag = cont.getValue().id.getValue().contains(searchtext.getText()) || cont.getValue().itemname.getValue().contains(searchtext.getText()) || cont.getValue().purity.getValue().contains(searchtext.getText()) || cont.getValue().location.getValue().contains(searchtext.getText()) || cont.getValue().weight.getValue().contains(searchtext.getText()) || cont.getValue().createdon.getValue().contains(searchtext.getText()) || cont.getValue().itemstatus.getValue().contains(searchtext.getText());
}else if(selected == "ID")
{
flag = cont.getValue().id.getValue().contains(searchtext.getText());
}else if(selected == "Item Name")
{
flag = cont.getValue().itemname.getValue().contains(searchtext.getText());
}else if(selected == "Purity")
{
flag = cont.getValue().purity.getValue().contains(searchtext.getText());
}else if(selected == "Location")
{
flag = cont.getValue().location.getValue().contains(searchtext.getText());
}else if(selected == "Gross weight")
{
flag = cont.getValue().weight.getValue().contains(searchtext.getText());
}else if(selected == "Created On")
{
flag = cont.getValue().createdon.getValue().contains(searchtext.getText());
}else if(selected == "Item Status")
{
flag = cont.getValue().itemstatus.getValue().contains(searchtext.getText());
}
return flag;
}
});
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
ObservableList<String> columnlist = FXCollections.observableArrayList("All","ID","Item Name","Purity","Location","Gross weight","Created On","Item Status");
columncombo.setValue("All");
columncombo.setItems(columnlist);
JFXTreeTableColumn<item,String> itemcol = new JFXTreeTableColumn<>("Item Name");
itemcol.setResizable(false);
itemcol.setSortable(false);
itemcol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<item, String>, ObservableValue<String>>(){
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<item, String> param) {
return param.getValue().getValue().itemname;
}
});
JFXTreeTableColumn<item,String> idcol = new JFXTreeTableColumn<>("ID");
idcol.setResizable(false);
idcol.setSortable(false);
idcol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<item, String>, ObservableValue<String>>(){
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<item, String> param) {
return param.getValue().getValue().id;
}
});
JFXTreeTableColumn<item,String> puritycol = new JFXTreeTableColumn<>("Purity");
puritycol.setResizable(false);
puritycol.setSortable(false);
puritycol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<item, String>, ObservableValue<String>>(){
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<item, String> param) {
return param.getValue().getValue().purity;
}
});
JFXTreeTableColumn<item,String> loccol = new JFXTreeTableColumn<>("Location");
loccol.setResizable(false);
loccol.setSortable(false);
loccol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<item, String>, ObservableValue<String>>(){
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<item, String> param) {
return param.getValue().getValue().location;
}
});
JFXTreeTableColumn<item,String> weightcol = new JFXTreeTableColumn<>("Gross Weight");
weightcol.setResizable(false);
weightcol.setSortable(false);
weightcol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<item, String>, ObservableValue<String>>(){
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<item, String> param) {
return param.getValue().getValue().weight;
}
});
JFXTreeTableColumn<item,String> createdoncol = new JFXTreeTableColumn<>("Created On");
createdoncol.setResizable(false);
createdoncol.setSortable(false);
createdoncol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<item, String>, ObservableValue<String>>(){
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<item, String> param) {
return param.getValue().getValue().createdon;
}
});
JFXTreeTableColumn<item,String> itemstatuscol = new JFXTreeTableColumn<>("Item Status");
itemstatuscol.setResizable(false);
itemstatuscol.setSortable(false);
itemstatuscol.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<item, String>, ObservableValue<String>>(){
@Override
public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<item, String> param) {
return param.getValue().getValue().itemstatus;
}
});
itempane.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue,Number newValue) {
idcol.setPrefWidth(((double) newValue / 7) - 15);
itemcol.setPrefWidth((double) newValue / 7);
puritycol.setPrefWidth((double) newValue / 7);
loccol.setPrefWidth((double) newValue / 7);
weightcol.setPrefWidth((double) newValue / 7);
createdoncol.setPrefWidth((double) newValue / 7);
itemstatuscol.setPrefWidth((double)newValue / 7);
hbox.setPrefWidth((double) newValue);
}
});
ObservableList<item> items = FXCollections.observableArrayList();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/gdlashmi?useSSL=false","root","");
PreparedStatement pst = (PreparedStatement) con.prepareStatement("SELECT id,product_name,Purity,location,gross_weight,Date(`date&time`),if(flag = 1, \"In Stock\", \"Sold Out\") `Item Status` from stocklist");
ResultSet rs = pst.executeQuery();
while(rs.next())
{
items.add(new item(rs.getString(2),String.valueOf(rs.getInt(1)),rs.getString(3),rs.getString(4),String.valueOf(rs.getDouble(5))+" Gram",String.valueOf(rs.getDate(6)),rs.getString(7)));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
final TreeItem<item> root = new RecursiveTreeItem<item>(items, RecursiveTreeObject::getChildren);
itemlist.getColumns().setAll(idcol,itemcol,puritycol,loccol,weightcol,createdoncol,itemstatuscol);
itemlist.setRoot(root);
itemlist.setShowRoot(false);
}
}
答案 0 :(得分:0)
您可以随时随地创建边框窗格作为fxml文件加载
答案 1 :(得分:0)
创建一个公共类,该类将接受您需要公开传递的数据
ChangeScenes.java
//changes the display in borderpane center
public static void moveToCenter(URL ui, BorderPane borderpane){
try {
Parent root = FXMLLoader.load(ui);
borderpane.setCenter(root);
} catch (IOException ex) {
Logger.getLogger(ChangeScenes.class.getName()).log(Level.SEVERE, null, ex);
}
}
然后您可以在任意位置调用它
MainController.java
@FXML private BorderPane borderPane;
@FXML
private void handlePersonalInfo(ActionEvent event) {
ChangeScenes.moveToCenter(getClass().getResource("/AnotherScene.fxml"), borderPane);
}