1

I'm french, sorry for mistake.

I have an primary stage, and foreground an small second stage. I want to color in gray all the primary stage when the second stage is visible.

It's good, i cannot click in the primary stage with the line :

stage.initModality(Modality.WINDOW_MODAL); 

But I want to put a color gray in the primary stage. I try to disable all componant in the primary stage (every componant is gray and disable) but imageViews are not gray, it's a problem.

Help please.

Thanks.

0

1 Answer 1

4

You can add all to a Stackpane and make a Region as a veil (visible=true/false).

import javafx.application.Application; import javafx.event.ActionEvent; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.Region; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class VeilDemo extends Application { @Override public void start(Stage primaryStage) { // that is the veil Region veil = new Region(); veil.setStyle("-fx-background-color: rgba(0, 0, 0, 0.3)"); veil.setVisible(false); Button btn = new Button(); btn.setText("Open Dialog"); btn.setOnAction((ActionEvent event) -> { Alert a = new Alert(Alert.AlertType.INFORMATION); //veil is only visible when alert window is showing veil.visibleProperty().bind(a.showingProperty()); a.setContentText("The main window should be decorated with a veil."); a.setX(primaryStage.getX() + 200); // This is only for showing main window a.showAndWait(); }); Image img = new Image("https://www.gnu.org/graphics/gnu-head-sm.png"); ImageView iv = new ImageView(img); // this should be the normal root of window BorderPane bp = new BorderPane(iv); bp.setBottom(btn); StackPane root = new StackPane(); root.getChildren().addAll(bp, veil); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } } 

The main window will look like this:

mainwindow

and if the button was clicked, the info window opens and the veil is visibile on the main stage.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.