我在一个项目中工作,我使用的dashboard.fxml包含一个拆分窗格。splitPane包含两个锚定窗格。左侧我没有几个选项卡,右侧我生成了view(这是其他一些FXML文件在afterburner.fx中使用视图)。 This is my dashboard.fxml, i generate the new view at the right side as shown in image.
这是我的DashboardPresenter.java文件
public class DashboardPresenter implements Initializable {
private ResourceBundle resources = null;
@FXML
private AnchorPane paneRegister;
@FXML
private AnchorPane paneRenewalMain;
@FXML
private AnchorPane paneAddOns;
@FXML
private AnchorPane paneReports;
@FXML
private AnchorPane paneEnquiryTab;
@Inject
private AddonPresenter addonPresenter;
//require views -----------------------------------------------------------------
EnquiryView enquiryView;
RegisterView registerView;
RenewalView renewalView;
ReportsView reportView;
public AddonView addOnView;
public DashboardPresenter(){
enquiryView = new EnquiryView();
if(paneEnquiryTab != null){
paneEnquiryTab.getChildren().add(enquiryView.getView());
paneEnquiryTab.setDisable(false);
paneEnquiryTab.setOpacity(1);
}
registerView = new RegisterView();
if(paneRegister != null){
paneRegister.getChildren().add(registerView.getView());
paneRegister.setDisable(false);
paneRegister.setOpacity(1);
}
renewalView = new RenewalView();
addOnView = new AddonView();
}
@Override
public void initialize(URL location, ResourceBundle resources) {
this.resources = resources;
}
public void clearAnchorPane(){
if(paneRegister != null){
paneRegister.getChildren().clear();
}
if(paneRenewalMain != null){
paneRenewalMain.getChildren().clear();
}
if(paneRenewalMain != null){
paneRenewalMain.getChildren().clear();
}
if(paneAddOns != null){
paneAddOns.getChildren().clear();
}
if(paneReports != null){
paneReports.getChildren().clear();
}
if(paneEnquiryTab != null){
paneEnquiryTab.getChildren().clear();
}
}
@FXML
private void onEnquiryTab(Event event) {
clearAnchorPane();
if(paneEnquiryTab != null){
paneEnquiryTab.getChildren().add(enquiryView.getView());
paneEnquiryTab.setDisable(false);
paneEnquiryTab.setOpacity(1);
}
}
@FXML
private void onRegistrationTab(Event event) {
clearAnchorPane();
paneRegister.getChildren().add(registerView.getView());
paneRegister.setDisable(false);
paneRegister.setOpacity(1);
}
@FXML
private void onRenewalTab(Event event) {
clearAnchorPane();
paneRenewalMain.getChildren().add(renewalView.getView());
paneRenewalMain.setDisable(false);
paneRenewalMain.setOpacity(1);
}
@FXML
private void onAddOnTab(Event event) {
clearAnchorPane();
paneAddOns.getChildren().add(addOnView.getView());
paneAddOns.setDisable(false);
paneAddOns.setOpacity(1);
}
@FXML
private void onReportTab(Event event) {
clearAnchorPane();
}
}
我想在左侧的定位面板上打开一个新的fxml文件。我可以轻松地做到这一点。如上面的代码所示(在onAddOnTab事件中)。 the view looks like this after inserting new view.
这是我的AddonPresenter.java。此文件是我的新视图Controller
public class AddonPresenter implements Initializable {
private ResourceBundle resources = null;
@FXML
private AnchorPane paneAddOnStartUp;
FreezeView freeze;
public AddonPresenter(){
freeze = new FreezeView();
}
public void clearAnchorPane(){
System.out.println("**************clearAnchorPane() AddonPresenter
initiated****************");
dashboard.clearAnchorPane();
if(paneAddOnStartUp != null){
paneAddOnStartUp.getChildren().clear();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
this.resources = resources;
}
@FXML
private void onFreezeClicked(MouseEvent event) {
System.out.println("**********************OnFreeze
Entered********************");
clearAnchorPane();
paneAddOnStartUp.getChildren().add(freeze.getView());
paneAddOnStartUp.setDisable(false);
paneAddOnStartUp.setOpacity(1);
}
}
现在,当我通过AddOn.fxml添加新视图时。我创建视图的多个实例。因此,当我从创建的第三个视图中按“后退”按钮时。this image shows the problem encountered.
FreezePresenter.java文件。该文件包含导致问题的后退按钮逻辑。
public class FreezePresenter implements Initializable {
private ResourceBundle resources = null;
@FXML
private AnchorPane paneFreezeMember;
@Inject
private AddonPresenter addonpresenter;
@Override
public void initialize(URL location, ResourceBundle resources) {
this.resources = resources;
}
@FXML
private void onBackButton(ActionEvent event) {
new AddonPresenter().clearAnchorPane();
AddonView addonView = new AddonView();
addonpresenter.clearAnchorPane();
paneFreezeMember.getChildren().add(addonView.getView());
paneFreezeMember.setDisable(false);
paneFreezeMember.setOpacity(1);
}
}
感谢您的帮助。