Class: DbUserController.cs
btnTamam.setOnAction((ActionEvent event) -> {
......
........
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("/View/PerformancePage.fxml"));
AnchorPane frame = fxmlLoader.load();
PerformancePageController c = (PerformancePageController) fxmlLoader.getController();
c.txtUrl.setText("TEST TEST");
});
txtUrl = PerformancePage.fxml TextField
c.txtUrl.setText("TEST TEST");
The code I'm pointing to is not working.
It does not write "TEST TEST" into TextBox.
You are loading a new pane:
AnchorPane frame = fxmlLoader.load();
But you aren't adding that pane to the displayed SceneGraph.
Related
How do I display an fxml file for some seconds and close that fxml file and return to the mainpage.fxml?
I have tried to add hideThispage method to the initialize method in the controller class of the fxml but I guess the initialize methods just runs before the class is actually loaded so I cannot run this code.
#FXML
public void hideThisPage() throws InterruptedException, IOException {
Window window = new Stage();
PauseTransition pause = new PauseTransition(Duration.seconds(5));
pause.setOnFinished(e -> window.hide());
pause.play();
FxmlDisplay fxmlDisplay = new FxmlDisplay();
fxmlDisplay.stageSelection("View/Main.fxml");
}
To return to the main.fxml or any fxml I have a method that I call:
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(path));
Parent root = fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
In my case, I have a print button in my printreceipt.fxml file that prints the contents. Then it switches to the printpage.fxml ( i am able to switch to the page) But my problem is the printpage.fxml is supposed to be displayed only for 5 seconds and close. then it should go back to main.fxml. how and where do I call the hidethisPage() method?
#FXML
void printRandomTicket(ActionEvent event) throws SQLException, ClassNotFoundException, JRException, IOException, InterruptedException {
FxmlDisplay fxmlDisplay = new FxmlDisplay();
((Node) event.getSource()).getScene().getWindow().hide();
fxmlDisplay.stageSelection("/View/Dialogs/PrintingTicket.fxml");
GenerateTicket generateTicket = new GenerateTicket();
generateTicket.generateTicket();
PrintTicket printTicket = new PrintTicket();
printTicket.printTicket();
}
I hope this clarifies it.
I got an Application or a screen where I can send E-Mails. I also got a template screen as a whole new window. For e.g. I already write 3 email addresses in the TO TextField. I want them to stay, even if I change the whole stage because when I then go to the TemplatePicker Screen and pick a template, the initialize will be called again in the EmailController and all recipicients in the TextField are gone.
Code E-Mail:
public void buttonPickTemplate(ActionEvent event) throws IOException {
Main.fxmlval.add("/application/controller/MailController/SendMail.fxml");
FXMLLoader loader = new FXMLLoader(getClass().getResource("/application/controller/TemplateController/TemplateAuswahlFenster.fxml"));
Parent parent = loader.load();
TemplateController templateController = loader.<TemplateController>getController();
templateController.setEmailVariablen(empfaengerField.getText(), ccField.getText(), bccField.getText(), betreffField.getText());
Scene homeScreenScene = new Scene(parent);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(homeScreenScene);
}
As you can see I tried to give the variables with a setter to the next screen and set them then back, but that would be horrible. Normally the method to change a screen always looks like this, if you have to throw no variables:
Parent detailsScreen = FXMLLoader.load(getClass().getResource("/application/controller/DetailsController/Details.fxml"));
Scene detailsScene = new Scene(detailsScreen);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(detailsScene);
So and this methode in the TemplateController calls again the EmailController and FXML:
public void auswaehlen(ActionEvent event)throws IOException
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("../MailController/SendMail.fxml"));
Parent homeScreen = loader.load();
MailSender wpc=loader.<MailSender>getController();
wpc.setTemplate(this.settemplate.getDatei());
Scene homeScreenScene = new Scene(homeScreen);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(homeScreenScene);
}
Hello I am having an JavaFX app with few controllers and I have 2 options to get back to previous screen. User can click button 'leave' or after finishing some tasks on this screen will be moved to previous automatically. I have problem here because I've created method wiut fxml annotation which takes ActionEvent object as parameter and is called when user click button and when user will finish tasks and should be moved automatically to previous screen I cannot call this method because I dont this object, it's created when an action - click in this case is made. How can I make it possible for both 'exit' options?
So here is my method which is used 'onAction' for my button:
#FXML
private void leaveRoomAction(ActionEvent event) {
try {
removePlayerFromRoom();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("LobbyView.fxml"));
Parent root = (Parent) loader.load();
LobbyController lobbyController = (LobbyController)loader.getController();
lobbyController.setClientThread(client);
lobbyController.setNameAndBalance(client.getPlayer().getName());
Scene scene = new Scene(root);
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
And later in other part of programe:
if(isFinished()){
//here I want write leaving this screen and getting back to previous
}
First, find another way to get a reference to the Stage. Since you almost certainly have a reference to some node in the scene in your controller, you can replace
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
with
Stage stage = (Stage) anyNode.getScene().getWindow();
where anyNode is just something you have injected into the controller.
Now you don't need the parameter at all, so you can just remove it. I.e. you end up with
#FXML
private Node anyNode ; // probably a more specific type than Node.
#FXML
private void leaveRoomAction() {
try {
removePlayerFromRoom();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("LobbyView.fxml"));
Parent root = (Parent) loader.load();
LobbyController lobbyController = (LobbyController)loader.getController();
lobbyController.setClientThread(client);
lobbyController.setNameAndBalance(client.getPlayer().getName());
Scene scene = new Scene(root);
Stage stage = anyNode.getScene().getWindow();
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
And now you can just call the method:
if ( isFinished() ) {
leaveRoomAction()
}
please i am trying to settext on a textfield after it as been open from login window but the changes it not displaying pls am new to java and javafx below is the code wich open the new window
try {
Statement stmnt= conn.createStatement();
rs=stmnt.executeQuery(sql);
if(rs.next()==true){
String name = null;
Image img = null;
name = rs.getString("name");
img = new Image(rs.getBinaryStream("photo"));
System.out.println(name);
Stage primaryStage = new Stage();
/*FXMLLoader loader = new FXMLLoader();
Pane root = loader.load(getClass().getResource("main.fxml").openStream());
mainController mnctrl = (mainController) loader.getController();
mnctrl.dispOpInfo(name, img);*/
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("main.fxml"));
Parent root = (Parent)fxmlLoader.load();
mainController controller = fxmlLoader.<mainController>getController();
controller.dispOpInfo(name, img);
primaryStage.show();
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("BECE 2017 Validation");;
primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
primaryStage.show();
//
}
and below is the code for the newly open window of it textfield is not changing at runtime
#FXML TextField txtSchName = new TextField();
public void populateCanInfo (String canSchool, String canName, String canState,String canGender, Image canPhoto){
System.out.println(canGender );
txtCanName.setText(canName);
txtSchName.setText(canSchool);
imgViewCan.setImage(canPhoto);
// int index=cmbCanState.getValue().indexOf(canState);
// cmbCanState.getSelectionModel().select(index);
if(canGender.equalsIgnoreCase(canGender)){
rbtMale.setSelected(true);
}else{
rbtFemale.setSelected(true);
}
}
I have Controller.java for Scene.fxml and ControllerSettings.java for WindowSettings.fxml. In Controller.java I create a new popup window (no dialog) with following method:
#FXML
public void handleSubmenuSettings(ActionEvent event) throws IOException {
Stage stage;
Parent root;
ControllerSettings controller;
stage = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("WindowSettings.fxml"));
root = (Parent) loader.load();
controller = (ControllerSettings) loader.getController();
stage.setScene(new Scene(root));
stage.setTitle("Settings");
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);
stage.initOwner(submenuSettings.getScene().getWindow());
stage.showAndWait();
stage.setOnCloseRequest(e -> {
e.consume();
controller.saveSettings();
stage.close();
});
}
I want to save the settings when closing the new popup window but that doesn't work with stage.setOnCloseRequest.
The showAndWait() method will block execution until the window has closed; i.e. subsequent statements will not be executed until after the window is closed. So you don't register the listener for the close request until after the window has been closed. Clearly, no request to close the window will occur after the window is closed, so your handler is never invoked.
It's not really clear why you are using a close request handler anyway. Presumably you simply want to call controller.saveSettings() after the window closes. Since you are using showAndWait() you can just do:
#FXML
public void handleSubmenuSettings(ActionEvent event) throws IOException {
Stage stage;
Parent root;
ControllerSettings controller;
stage = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("WindowSettings.fxml"));
root = (Parent) loader.load();
controller = (ControllerSettings) loader.getController();
stage.setScene(new Scene(root));
stage.setTitle("Settings");
stage.initModality(Modality.APPLICATION_MODAL);
stage.setResizable(false);
stage.initOwner(submenuSettings.getScene().getWindow());
stage.showAndWait();
controller.saveSettings();
}