JavaFX 获取屏幕尺寸

package fx.com;

import javafx.application.Application;
import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import javafx.geometry.Rectangle2D;
import javafx.stage.Screen;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) {
        launch(Main.class,args);
    }
    @Override
    public void start(Stage primaryStage){
        //获取屏幕信息
        //获取主屏幕
        Screen screen = Screen.getPrimary();
        double dpi = screen.getDpi();
        System.out.println("屏幕的分辨率:"+dpi);
        //获取整个屏幕的尺寸
        Rectangle2D bounds = screen.getBounds();
        //获取可视屏幕范围的尺寸
        Rectangle2D visualBounds = screen.getVisualBounds();
        //下面是全部屏幕的高度和坐标
        System.out.println("左上角X"+bounds.getMinX()+"\t左上角Y="+bounds.getMinY());
        System.out.println("右下角X"+bounds.getMaxX()+"\t右下角Y="+bounds.getMaxY());
        System.out.println("尺寸"+bounds.getWidth()+"x"+bounds.getHeight());

        //下面是可视屏幕的高度和坐标
        System.out.println("左上角X"+visualBounds.getMinX()+"\t左上角Y="+visualBounds.getMinY());
        System.out.println("右下角X"+visualBounds.getMaxX()+"\t右下角Y="+visualBounds.getMaxY());
        System.out.println("尺寸"+visualBounds.getWidth()+"x"+visualBounds.getHeight());
        primaryStage.show();
    }
}

你可能感兴趣的:(JavaFX)