2016-07-20 72 views
0

我是法国人,很抱歉有错。禁用后台阶段javafx

我有一个初级阶段,前景中的小第二阶段。当第二阶段可见时,我想以灰色着色所有初级阶段。

这是很好的,我不能在初级阶段点击与在线:

stage.initModality(Modality.WINDOW_MODAL); 

但我想提出一个灰色的初级阶段。 我尝试在主阶段禁用所有组件(每个组件都是灰色的并禁用),但imageViews不是灰色的,这是一个问题。

请帮忙。

谢谢。

回答

0

您都可以添加到一个Stackpane,使区域的面纱(可见= 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); 
    } 

} 

主窗口将显示如下:

mainwindow

,如果被点击的按钮,打开信息窗口和面纱都看得到的主舞台。

enter image description here