How customize the chart from another window in JavaFX - javafx

I'm new at Stackoverflow and Javafx (and Java at all), so my question can be stupid.
I have a .fxml file with main window (it's include LineChart) and Controller.java, binded to it. And I need make new window with chart options (color and thickness of line). I'm making window with options by event, binded on menuItem in main window.
So, how I can change properties of chart in main window from options window?
I don't understand at all how to get access to LineChart in main window!
This is how I open options window:
void showSettings(ActionEvent event)
throws IOException {
Group root = new Group();
Stage stage = new Stage();
AnchorPane frame = FXMLLoader.load(getClass().getResource("options.fxml"));
root.getChildren().add(frame);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
Can anybody help me?
P.S. Sorry for my bad English level :c
Edit1: I need pass params from new window(options) to already existing (main)!

Related

How to load new FXML as a popup box in javaFX

I am new in JavaFX, I fetched database value into table view form after that when I click on table row then I want to load another FXML page and load the database value into textfield.
To load another FXML file and show it in a new opened window (Main.class.getResource(...) has to be adjusted):
Stage stage = new Stage();
Parent root = FXMLLoader.load(Main.class.getResource("your.fxml")));
stage.setTitle("...");
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();

Open a javafx fxml file in separate window on a button click without duplication

I use the below code to open a javafx fxml file in a different window on a button click event and it works fine. But if I click the same button again while the window opened it will create a duplicate window. Is there a possibly solutions to overcome this problem? Thanks in advance.
Parent parent = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Stage stage = new Stage(StageStyle.DECORATED);
stage.setTitle("Title");
stage.setScene(new Scene(parent));
stage.show();
I just stumbled upon this old question and figured I might answer it for anyone new to JavaFX or coding in general (I'm bored..).
In the provided code (see below) a new Stage is created every time, meaning that if this is run inside of a method you actually create a new Stage variable every time that the code is run:
Stage stage = new Stage(StageStyle.DECORATED);
What you could do instead create your Stage variable outside the method so that you either 1. just overwrite it every time or 2. have some "is showing" or a nullcheck or similar to see if a new stage should be created or if the existing one just needs to be shown.
For example:
private Stage stage;
private void onOpenNewStageBtnClicked(){
if(stage == null){
Parent parent = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
stage = new Stage(StageStyle.DECORATED);
stage.setTitle("Title");
stage.setScene(new Scene(parent));
}
stage.show();
}
Also, what I usually do is I create a Stage factory to avoid a lot of duplicate code and so that I can break out the creation of the stages and the loading of fxmls to other classes than my controller.

JavaFX - How to open a new stage in same window?

I'm a beginner, I don't know how to open a new stage in same window in javaFX8?
Stage modal_stage = new Stage();
modal_stage.setScene(new Scene(root, 500, 575));
modal_stage.setTitle("modal");
modal_stage.initModality(Modality.APPLICATION_MODAL);
modal_stage.initOwner(modal_stage.getOwner());
modal_stage.setResizable(false);
modal_stage.show();
When I opened a new stage through the above code, the stage always opening in a difference window,like this:
But I want the new stage will not create a new icon in StartMenu taskbar, just like Swing's Dialog of Jframe---No matter how many dialogs I open under jframe, It is always displayed as one window. So what can I do?
Sorry, I am not very good at English, I wish I had clarified the question.
Assuming that you have a parent stage:
Stage parentStage = new Stage();
And the child Stage:
Stage childStage = new Stage();
You have to set the init owner of the childStage to be the parent:
childStage.initOwner(parent);
Mention that the above has to be called before the childStage to be shown.
Also mention that doing this you will have some behaviour like when parent child is minimized then childStage will be also minimized.

I need to create a back button functionality in javafx?

I am presently using something like this binding this code to fxml javafx button
Parent parent = FXMLLoader.load(getClass().getResource("AolRun.fxml"));
Stage stage = new Stage();
stage.initStyle(StageStyle.UTILITY);
stage = (Stage) run.getScene().getWindow();
Scene scene = new Scene(parent);
stage.setScene(scene);
scene.getStylesheets().add("/css/Style.css");
stage.setTitle("Output");
stage.setResizable(false);
stage.show();
Is there a generic function we can use for back which just transits screen from the present fxml scene to the next fxml .
I have separate scene for every fxml.
1)A better approach is to change the parent layout and use only one Scene.
2)Although you can have the functionality you want using a Button.When the onAction method is fired you choose in what Scene to go.You can either have the Scenes stored in the array and move to the next or previous index, or implement your own logic which Scene will follow or which Scene is the previous of the current Scene.
Here is where the 1 is more usefull cause you can go to the next or previous "Scene" using an Animation.For example TransitionAnimation.
~~> In addition to the comments below
If you want to know in which Scene was the user before you can use an ObservableList or Array.
Everytime the user changes Scene ,the previous Scene is stored in the array.

javafx retain root while adding a secondary stage

I have a growing application with a menu bar with Home, Chapters, Calculator, Glossary, Help. Everything is working fine including the Chapters with 14 items.
Also the Calculator that is a source package. It opens but I lose the stage. I would like it to open and able to be dragged around the screen.
This is the code I am using:
else if(e.getSource()==mbarcalculator){
stage = (Stage) root.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("/javafxcalc/FXMLcalc.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
I have read a lot of posts but haven't found a simple answer.
After a lot of patience and perseverance I have a solution that works and one I can understand.
else if(e.getSource()==mbarcalculator){
Stage secondaryStage = new Stage();
Parent root2 = FXMLLoader.load(getClass().getResource("/javafxcalc/FXMLcalc.fxml"));
Scene scene2 = new Scene(root2);
secondaryStage.setScene(scene2);
secondaryStage.show();
}
I took a small section of code from Jose Pereda's answer Display two windows at the same time "on fullscreen" with JavaFx Scene Builder 2.0
I have tested it and it works nicely.

Resources