When I run my code in Eclipse every window opens with no problems.
First Window leads to the second, and the second leads to the third.
When I made my jar executable and started the application again, the transition from the first to the second windows went the same way as in the eclipse, however, when I clicked Start on a second window, the third window never showed up.
This is what Start Button is responsible for:
((Stage)Start.getScene().getWindow()).close();
Stage primaryStage = new Stage();
primaryStage.setTitle("Board");
primaryStage.getIcons().add(new Image("Media/logo.png"));
FXMLLoader loader = new FXMLLoader();
loader.setLocation(GameModeController.class.getResource("Board.fxml"));
BorderPane mainLayout = loader.load();
Scene scene = new Scene(mainLayout);
primaryStage.setScene(scene);
controller.RedSpyMasterTerm();
primaryStage.setOnCloseRequest(e->System.exit(0));
primaryStage.show();
First Window: https://i.stack.imgur.com/Z0rf4.png
Second Window: https://i.stack.imgur.com/LLOZm.png
Third Window: https://i.stack.imgur.com/SxBPg.png
Location of the files: https://i.stack.imgur.com/LeEn3.png
https://i.stack.imgur.com/hPU9p.png
Related
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?
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 create a simple login form to checking username and password.
I did it and my problem is while checking the username and password is correct open new fxml window.
Can anyone drop some simple code to solve it.
So, below is just an example to get you started but what I usually do is I create some sort of a stage factory so that I don't have a lot of duplicate code.
Let me know if you have any questions.
My example:
if(/*your if condition*/){
YourController controller = new YourController();
FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(fxmlPath));
loader.setController(controller);
Parent root = loader.load();
Scene scene = new Scene(root, width, height, Color.WHITE);
Stage stage = new Stage();
stage.setX(xPos);
stage.setY(yPos);
stage.setScene(scene);
stage.show();
}
Edit, I felt nice today but I do agree with the first comment that you received. Remember to read through the guide lines next time.
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 wish to remove some of the control buttons from HTMLEditor, since I do not need them. for that I need to reach the desired node. How can I know the IDs of nodes inside HTMLEditor? Please see the following. Thank you!
public class myApp extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("myApp.fxml")); //this fxml has HTMLEditor named htmlEditor.
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
Node someControlInsideHtmlEditor = root.lookup("#htmlEditor").lookup("#what_Is_The_ID_of_This_someControlInsideHtmlEditor")
}
}
Download Scenic View from here
Add this to your application's class path
Add the following line to your start() method's end:
ScenicView.show(scene);
Run the application
Two windows will pop up: the primaryStage with the HTMLEditor and Scenic View's Stage
Now you can visit every node of the Scene Graph. Open the tree at the left pane, and select a Node from the HTMLEditor. You can access the controls by their CSS class.
For example, open HTMLEditor -> ToolBar -> HBox, and select the first Button. Look at "styleClass" in the "Node Details" at the right side. You will need "html-editor-cut". It can be used with this code:
Button cutButton = (Button) root.lookup(".html-editor-cut");
don't know if you're still looking for this answer. In Java 8, and HTMLEditor only has one child, which is a GridPane. The first two children of that are the ToolBars, the third is a WebView. Remove the first two children from the gridpane to do the formatting you want. Does that help?