需要用到JavaFX
// 初始化 JavaFX toolkit
new JFXPanel();
Platform.runLater(() -> {
Screen screen = Screen.getPrimary();
// 获取默认屏幕设备
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode dm = gd.getDisplayMode();
int physicalWidth = dm.getWidth();
int physicalHeight = dm.getHeight();
javafx.geometry.Rectangle2D visualBounds = screen.getVisualBounds();
int logicalWidth = (int) visualBounds.getWidth();
int logicalHeight = (int) visualBounds.getHeight();
double scaleX = (double) physicalWidth / logicalWidth;
double scaleY = (double) physicalHeight / logicalHeight;
Platform.exit();
});