JavaFx pane in pane resizing

被刻印的时光 ゝ 提交于 2019-12-11 05:14:49

问题


How I can resize Pane in GridPane? I'm creating a GUI which is GridPane and a map in it. And when gui change it's size I want to map which is in another Pane to resize. So I've added listners to width and height property of scene and there are generaly working. When I do setTranslateX of map I can see that something changed, but resizing not works at all. It can be caused by fact that map contains from tiles which have their size set. Code of method which create the scene:

private Scene createScene(GridPane root){
    Scene scene = new Scene(root, WIDTH_OF_SCENE, HEIGHT_OF_SCENE);
    scene.widthProperty().addListener((observableValue, oldSceneWidth, newSceneWidth) -> {
        WIDTH_OF_SCENE = newSceneWidth.intValue();
        draw();
        MAP_PANE.setPrefSize(200, 200); //it's not working
        MAP_PANE.setTranslateX(0); //it's working 
        root.requestLayout();
    });

    scene.heightProperty().addListener((observableValue, oldSceneHeight, newSceneHeight) ->{
        HEIGHT_OF_SCENE = newSceneHeight.intValue();
        draw();
        root.requestLayout();
    });
    return scene;
}

And here I'm creating MAP_PANE:

public Pane createContent() {
    map = new Pane();
    map.setStyle("-fx-background-color: #383838");

    // dodawanie pojedynczych kafli do dwuwymiarowej tablicy
    for (int y = 0; y < Y_TILES; y++) {
        for (int x = 0; x < X_TILES; x++) {
            Tile tile = new Tile(x, y);
            grid[x][y] = tile;
            map.getChildren().addAll(tile);
        }
    }
    return map;
}

And start method:

@Override
public void start(Stage primaryStage) throws Exception{
    Map map = new Map();
    GridPane root = FXMLLoader.load(getClass().getResource("sample.fxml"));

    MAP_PANE = map.createContent();
    IMAGE_VIEW = new ImageView();

    countScreenSize();
    draw();

    root.getChildren().addAll(IMAGE_VIEW);
    root.getChildren().addAll(MAP_PANE);

    primaryStage.setTitle(TITLE);
    primaryStage.setScene(createScene(root));
    primaryStage.show();
}

来源:https://stackoverflow.com/questions/46018344/javafx-pane-in-pane-resizing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!