JavaFX setAlwaysOnTop on a fullscreen stage - java

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.

Related

Changing scenes with Alert JavaFX

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?

Can I change Scene using JavaFX automatically?

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();
}

How to set a window always on top of another specific window in javafx

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();
}

Why javafx setResizeable(false) not work?

I have a javafx code like this
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/view/Login.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Welcom to MSS Login");
stage.setResizable(false);
stage.show();
}
Here I already setResizable(false); but I still can resize the window when run app. How to set a window not resizeable?
Thanks
I came across this problem today, trying to create some windows for my database management system and I clearly wanted fixed window size, non resizable, but unfortunately this is not fully supported by Ubuntu 16.04 LTS, which seems to have a different approach to how it performs with window size handlers.
However, I found the fix after none of stageStyle("TRANSPARENT"), setResizable(false) did not work.
The second one would normally work on Windows.
The fix for Ubuntu:
primaryStage.setMaxHeight(yourH);
primaryStage.setMinHeight(yourH);
primaryStage.setMaxWidth(yourW);
primaryStage.setMinWidth(yourW);

How to get the IDs of nodes inside HTMLEditor, JavaFX

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?

Categories