I'm new in JavaFX
, so I need some help in sharing data between two controllers.
I have simple window which has simple menu:
@FXML
Label labelLabel;
@FXML
MenuItem sbor;
@FXML
MenuItem alim_poluch;
@FXML
MenuItem paragraphs;
@FXML
MenuItem poluch_cat;
@FXML
MenuItem visluga_vid;
@FXML
AnchorPane menuPane;
@FXML
MDICanvas mdiCanvas;
@FXML
Tab tabOne;
@FXML
VislugaVidController vid;
@FXML
Tab tabTwo;
@FXML
public void initialize() {
MDICanvas mdiCanvas = new MDICanvas(MDICanvas.Theme.DEFAULT);
menuPane.getChildren().add(mdiCanvas);
AnchorPane.setBottomAnchor(mdiCanvas, -1d);
AnchorPane.setLeftAnchor(mdiCanvas, 0d);
AnchorPane.setTopAnchor(mdiCanvas, 0d);//Button place
AnchorPane.setRightAnchor(mdiCanvas, 0d);
sbor.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
Stage stage = new Stage();
AnchorPane pane = null;
try {
pane = FXMLLoader.load(getClass().getResource("/fxml/spr_pocht_sbor.fxml"));
} catch (IOException e) {
System.err.print("Can't open the resource file");
e.printStackTrace();
}
stage.setTitle("Почтовый сбор для перевода алиментов");
stage.setResizable(false);
Scene scene = new Scene(pane, 600, 450);
stage.setScene(scene);
stage.show();
}
});
alim_poluch.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
Stage stage = new Stage();
AnchorPane pane = null;
try {
pane = FXMLLoader.load(getClass().getResource("/fxml/spr_alim_poluch.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
stage.setResizable(false);
stage.setTitle("Справочник получателей алиментов");
Scene scene = new Scene(pane, 800, 640);
stage.setScene(scene);
stage.show();
}
});
paragraphs.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
Stage stage = new Stage();
AnchorPane pane = null;
try {
pane = FXMLLoader.load(getClass().getResource("/fxml/paragraf.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
stage.setResizable(false);
stage.setTitle("Параграф назначения денежных средств");
Scene scene = new Scene(pane, 300, 450);
stage.setScene(scene);
stage.show();
}
});
poluch_cat.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
Stage stage = new Stage();
AnchorPane pane = null;
try {
pane = FXMLLoader.load(getClass().getResource("/fxml/poluch_cat.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
stage.setResizable(false);
stage.setTitle("Категории получателей");
Scene scene = new Scene(pane, 600, 450);
stage.setScene(scene);
stage.show();
}
});
visluga_vid.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
AnchorPane content = null;
try {
content = FXMLLoader.load(getClass().getResource("/fxml/visluga_vid.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
MDIWindow mdiWindow = new MDIWindow("1", new ImageView("/assets/WindowIcon.png"), "Виды выслуг", content);
Button buttonMaximize = mdiWindow.getBtnMaximize();
buttonMaximize.setDisable(true);
mdiWindow.setMaxSize(350, 450);
mdiWindow.setBtnMinimize(buttonMaximize);
mdiCanvas.addMDIWindow(mdiWindow);
}
});
}
When I click at menuItem visluga_vid.setOnAction
new mdi windows
is opening. Then I want to open another window from mdi window
. MdiWindows
has parent (MDICanvas
), and the MDICanvas
has parent - AnchorPane
. MDIWIndows
has it's own controller and fxml
file.
public class VislugaVidController {
@FXML
TableView vislugaVidTable;
@FXML
TextField naim_vislugaField;
@FXML AnchorPane menuPane;
@FXML
public void initialize() {
//main.init(this);
vislugaVidTable.setOnMousePressed(event -> {
if (event.isPrimaryButtonDown() && event.getClickCount() == 2) {
System.out.println(vislugaVidTable.getSelectionModel().getSelectedItem());
AnchorPane content = null;
try {
content = FXMLLoader.load(getClass().getResource("/fxml/visluga_nadb.fxml"));
} catch (IOException e) {
e.printStackTrace();
}
MDIWindow mdiWindow = new MDIWindow("1", new ImageView("/assets/WindowIcon.png"), "Надбавки", content);
Button buttonMaximize = mdiWindow.getBtnMaximize();
buttonMaximize.setDisable(true);
mdiWindow.setMaxSize(350, 450);
mdiWindow.setBtnMinimize(buttonMaximize);
mdiCanvas.addMDIWindow(mdiWindow);
}
});
}
}
How can I share AnchorPane and MDICanvas
from MainController
to MDIWindowController
to open new MDIWindow
?