đề cập rằng:
1) Bạn phải sử dụng xây dựng trong bố trí JavaFX (BorderPane, GridPane .... vv ...)
2) Không có automaticall.You phải lập trình nó để làm như vậy.
3) Người ta thường ví dụ mà bạn muốn biết màn hình (chiều rộng hoặc chiều cao) mà không có thanh tác vụ (trong Windows, Linux, Mac, Solaris) .Tại trường hợp đó bạn chơi với getVisualBounds()...
chính theme
bạn đang hỏi về Responsive Design .Below là một ví dụ về những gì bạn muốn make.Although không phải là giải pháp tốt nhất, với điều này tôi có nghĩa là nó có thể được sửa đổi cho hiệu suất tốt hơn (tôi cũng đã bổ sung thêm một số mã di chuyển cửa sổ nếu nó là StageStyle.UNDECORATED
Kéo cửa sổ đã thấy điều này):
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);
}
}
Nhưng làm thế nào ứng dụng sẽ thay đổi kích thước nếu tôi có bên trong thư mục gốc Chánh Pane khác và TabPane và TableView đó sẽ được đặt trên khía cạnh này? Sẽ tự động thay đổi kích thước? –
Bạn cần phải làm cho những tỷ lệ của kích thước màn hình cũng như iirc. –