返回

java-如何更改网格窗格中节点的位置

发布时间:2022-04-25 04:45:19 283
# 移动端

我有一个4x4 gridpane对象,它由Tiles组成,扩展了ImageView,我想创建一个方法,通过鼠标拖放来改变连接的Tiles的位置。我已经知道了如何获取开始拖动的第一个元素,但我无法获取拖放的ImageView的引用。

瓷砖类

public class Tile extends ImageView {
    protected int xCoordinate;
    protected int yCoordinate;
    protected boolean isMoveable;
    
    protected ArrayList points = new ArrayList<>();
    

    public Tile(int xCoordinate, int yCoordinate) {
        this.xCoordinate = xCoordinate;
        this.yCoordinate = yCoordinate;
        super.setFitHeight(125);
        super.setFitWidth(125);
    }}

网格窗格代码

GridPane gridPane = new GridPane();
for (Tile tile : tiles){
    gridPane.add(tile,tile.getXCoordinate(),tile.getYCoordinate());
}
StackPane centerPane = new StackPane();
centerPane.setStyle("-fx-background-color: white;");
centerPane.getChildren().add(gridPane);
centerPane.setPadding(new Insets(0,50,0,50));

我已经试过了,但我不知道如何获得连接瓷砖的参考

        gridPane.setOnMouseDragged(e->{
        System.out.println(e.getTarget());

        gridPane.setOnMouseReleased(e1->{
            System.out.println(e1.getTarget());
        });
    });

我已经创建了更改位置的代码,但我应该在鼠标释放时获得连接的互动程序的引用。

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像