我有以下问题:
我在全高清桌面上创建了一个JavaFX
窗口,场景设置如下:
Scene scene = new Scene(root,1475,1015);
当我在使用1360*760
分辨率的笔记本电脑上运行应用程序时,我看不到整个应用程序,也无法调整它的大小。
如何根据台式机/笔记本电脑及其分辨率和尺寸将应用程序设置为自动调整大小?
发布于 2016-10-29 23:09:28
我相信你在找这个
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
这将允许你使用你的设备的屏幕尺寸,你需要做的就是使程序中对象的长度/宽度与屏幕的宽度和高度成比例。
发布于 2016-10-29 23:37:10
提到:
getVisualBounds()...
主主题
你在问Responsive Design.Below是什么例子,你想make.Although不是最好的解决方案,我的意思是可以修改它以获得更好的性能(我还添加了一些代码来移动窗口,如果它是StageStyle.UNDECORATED
的话拖动窗口就会看到这个):
import javafx.application.Application;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class FX extends Application {
int screenWidth = (int) Screen.getPrimary().getBounds().getWidth();
int screenHeight = (int) Screen.getPrimary().getBounds().getHeight();
Stage stage;
Scene scene;
int initialX;
int initialY;
@Override
public void start(Stage s) throws Exception {
// root
BorderPane root = new BorderPane();
root.setStyle("-fx-background-color:rgb(186,153,122,0.7); -fx-background-radius:30;");
// Responsive Design
int sceneWidth = 0;
int sceneHeight = 0;
if (screenWidth <= 800 && screenHeight <= 600) {
sceneWidth = 600;
sceneHeight = 350;
} else if (screenWidth <= 1280 && screenHeight <= 768) {
sceneWidth = 800;
sceneHeight = 450;
} else if (screenWidth <= 1920 && screenHeight <= 1080) {
sceneWidth = 1000;
sceneHeight = 650;
}
// Scene
stage = new Stage();
stage.initStyle(StageStyle.TRANSPARENT);
scene = new Scene(root, sceneWidth, sceneHeight, Color.TRANSPARENT);
// Moving
scene.setOnMousePressed(m -> {
if (m.getButton() == MouseButton.PRIMARY) {
scene.setCursor(Cursor.MOVE);
initialX = (int) (stage.getX() - m.getScreenX());
initialY = (int) (stage.getY() - m.getScreenY());
}
});
scene.setOnMouseDragged(m -> {
if (m.getButton() == MouseButton.PRIMARY) {
stage.setX(m.getScreenX() + initialX);
stage.setY(m.getScreenY() + initialY);
}
});
scene.setOnMouseReleased(m -> {
scene.setCursor(Cursor.DEFAULT);
});
stage.setScene(scene);
stage.show();
}
/**
* Main Method
*
* @param args
*/
public static void main(String[] args) {
launch(args);
}
}
发布于 2018-04-22 03:57:04
你可以这样做:
primaryStage.setMaximized(true);
https://stackoverflow.com/questions/40320199
复制相似问题