JavaFx:4、進一步認識stage窗口,模式,模態


package fx.com;

import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
//        primaryStage.setOpacity(1); // 設置窗口的透明度
//        primaryStage.setAlwaysOnTop(true); // 設置窗口置頂
//        // 獲取屏幕的寬度和高度
//        Screen primary = Screen.getPrimary();
//        Rectangle2D bounds = primary.getBounds();
//
//        primaryStage.show();
//        // 窗口居中顯示
//        primaryStage.setX((bounds.getWidth()-primaryStage.getWidth())/2);
//        primaryStage.setY((bounds.getHeight()-primaryStage.getHeight())/2);

        Stage s1 = new Stage();
        //具有純白色背景和平台裝飾的舞台。
        s1.initStyle(StageStyle.DECORATED);
        s1.setTitle("s1");
        s1.show();

        Stage s2 = new Stage();
        //一個純白色背景且沒有裝飾的舞台。
        s2.initStyle(StageStyle.UNDECORATED);
        s2.setTitle("s2");
        s2.show();

        Stage s3 = new Stage();
        //具有透明背景且沒有裝飾的舞台。
        s3.initStyle(StageStyle.TRANSPARENT);
        s3.setTitle("s3");
        s3.show();

        Stage s4 = new Stage();
        //具有純白色背景和最少平台裝飾的舞台。
        s4.initStyle(StageStyle.UTILITY);
//        s4.initModality(Modality.APPLICATION_MODAL); //模態窗口
        s4.initOwner(s1);
        // 子窗口的模態對話框
        s4.initModality(Modality.WINDOW_MODAL);
        s4.setTitle("s4");
        s4.show();
        s4.centerOnScreen(); //設置居中

    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM