2016-07-20 71 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