I'm using JavaFX and trying to make a small GUI application where the user can interact with spacetraders.io API.
I've implemented an Alert dialog box when the user attempts to make any transaction (purchase a ship, obtain a loan, purchase goods, sell goods...), and once the user has confirmed their transaction, the stage will be switched to a stage that displays the results of the transaction when shown.
Correct Display
The Alert dialog box functions fine but the switching of stage presents an issue. When I switch the stage, the full scene is not loaded for some odd reason, the back button is chopped off.
Chopped Off Display
When I then click anywhere on the window, the stage is fully shown as in the first image. (all it takes is one click anywhere inside the window).
When I remove the Alert, the stage loads fine. But when I put the same code into an ifPresent lambda, the stage fails to load fully/properly.
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Are you sure you want to obtain this loan?");
alert.showAndWait().ifPresent(response -> {
if (response == ButtonType.OK) {
BorderPane borderPane = new BorderPane();
//make title, backbtn, res
borderPane.setTop(title);
borderPane.setBottom(backBtn);
borderPane.setCenter(res);
Scene scene = new Scene(borderPane, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
event.consume();
}
});
I've looked at the docs and I can't seem to figure out why this is the case? Any solutions are welcome?
Related
I have a main stage with these properties. It is meant to be a secure "lockdown stage"
public static Stage getSecureStage(Window window) throws IOException {
Stage stage = new Stage();
//Take up the entire screen boundaries
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
stage.setHeight(visualBounds.getHeight());
stage.setWidth(visualBounds.getWidth());
//Secure the stage
stage.setFullScreen(true);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
stage.setFullScreenExitHint(null);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(getScene(window));
return stage;
}
With this lockdown stage, I want to be able to have popup windows within the stage stay on top
As you can see, the stage initializes on top of the lockdown stage. However, if I am to click off of that popup and back onto the main lockdown stage, the lockdown stage takes priority and puts itself over the popup. It does not minimize it, but just goes on top.
I have given the popup the properties
popup.setAlwaysOnTop(true);
popup.initOwner(lockdownStage);
however, that does not seem to do the trick. I had not previously had this issue running on Linux, with the same code. Please let me know if you need anymore information
Solved this by getting rid of the
stage.setFullScreen(true);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
stage.setFullScreenExitHint(null);
and setting it instead to
stage.setMaximized(true);
With the previous fullscreen setup, you could also use the stage.initModality(Modality.APPLICATION_MODAL); on the popup window. In my case, I wanted to be able to interact with both windows not singling one out with the modality feature.
I am trying to make a game as my term final project. So when life level of one player is less or equal zero then I am trying to load another fxml file on the existing stage automatically. But I can't . I am not sure that if-else logic can change one scene to another. It will be helpful if anyone can give a way to change a scene automatically.
enter image description here
Thanks in advance.
if(Controller.lifeDekhao2<=0){
Parent is = FXMLLoader.load(getClass().getResource("/FXMLPack/First1.fxml"));
Scene isScene = new Scene(is);
Stage window = (Stage) ((Node) (event.getSource())).getScene().getWindow();
window.setScene(isScene);
window.show();
Controller.time_end = System.currentTimeMillis();
}
I have a toolbox that needs to stay always on top of the main window, but not of any other windows. So what I would need is a .setAlwaysOnTop(true) but for a specific window. How do I do that?
When you create the second Stage you have to call initOwner and initModality with Modality.WINDOW_MODAL. Then the new stage is always on top of the other but you can't interact with the parent stage.
For example:
public void createNewStage(Window parent) {
//... all the other stuff
Stage onTop = new Stage();
onTop.initOwner(parent);
onTop.initModality(Modality.WINDOW_MODAL);
onTop.show();
}
I am new to Java FX and trying to build up an "easy" application which consists of a header button bar and a "content area" below.
I've managed a big part like that:
MainWindow.fxml with a Borderpane: MenuBar in the Top Area
And a Pane with fx:id: content in the center area.
Several X.fxml files for the content ()
One Controller which creates the obj content:
#FXML
private Pane content;
and switches the content:
content.getChildren().clear();
content.getChildren().add(FXMLLoader.load(getClass().getResource("Navi.fxml")));`
Main file which initializes the parent and scene:
Parent root = FXMLLoader.load(getClass().getResource("MainWindow.fxml"));
Stage Window = primaryStage;
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
Window.setTitle("ICIS - In Car Interactive System");
Window.setScene(scene);
Window.show();`
So far everything works fine!
But now I want to apply a SplitPane and do the "content change" in each side of the Split Pane (TwoWindows.fxml): So I've extended the
Controller with obj. for every Pane of the Split Pane, assigned the fx:id to that pane and want to control them analog to the example before.
#FXML
private Pane SecondWindow1;
SecondWindow1.getChildren().add(FXMLLoader.load(getClass().getResource("Navi.fxml")));
Well, during compilation everything is fine, but while running I get the Null error exception, so that I assume SecondWindow1 (left half of SlitPane) is not known to the controller.
I also assume, it is because I initialize at the beginning only MainWindow.fxml (which includes the content area) but not the TwoWindows.fxml (SplitPane) which inlcude the SecondWindow1 Object.
Well I've tried since hours now to solve it, but apparently I am overlooking sth. Somebody knows how to fix that problem? Do I need one Controller for every FXML File?
Code is at https://bpaste.net/show/b7aa0530f2ac (because of StackOverflow limitations)
I'm currently trying to use
//Menu.java
btn.setOnAction(event -> {
primaryStage.setScene(doubleclick);
});
to change scene from current scene to Scene doubleclick but it isn't found because it is in another class (Mouse.java). Also the variables in that class are needed for it to work. I've tried to copy over the code from Mouse.java to Menu.java but I don't know how to make that work.
So when I click button in the image above I see what is below:
...instead of the first content (main menu).