java - 如何在JavaFx中移动工具栏中的图像

标签 java javafx toolbar

我想知道是否有人知道如何将工具栏中的图像稍微向右移动,这样它就不会太靠近 Pane 的边缘。

这是我目前拥有的:/image/vZnzX.png

我希望它仅向右移动几个像素,以便它位于工具栏的更中心位置。

我当前使用分配给标签的 ImageView 来在工具栏中显示图像

感谢您的帮助

这是我的代码:

Image robotIcon = new Image(getClass().getResourceAsStream("robot-16.png"));
ImageView robotView = new ImageView(robotIcon);
robotView.setFitHeight(50);
robotView.setFitWidth(50);

Label robotImage = new Label("");
    robotImage.setGraphic(robotView);



ToolBar toolBar2 = new ToolBar();
    toolBar2.setOrientation(Orientation.VERTICAL);
    toolBar2.getItems().addAll(
            controlLabel,
            new Separator(),
            gameLabel,
            rdoStart,
            rdoStop,
            new Separator(),
            animationLabel,
            rdoRestart,
            new Separator(),
            simulationLabel,
            btnRobot,
            delRobot,
            new Separator(),
            robotLabel,
            difSizeRobot,
            sameSizeRobot,
            new Separator(),
            robotSpeedLabel,
            difSpeedRobot,
            sameSpeedRobot,
            new Separator(),
            objectSpawnLabel,
            solidObject,
            solidCircle,
            robotImage
        );

最佳答案

最简单的解决方案就是在标签上添加一些填充:

robotImage.setPadding(new Insets(0, 0, 0, 5));

关于java - 如何在JavaFx中移动工具栏中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47953077/

相关文章:

java - getTableCellRendererComponent 被反复调用并使 CPU 使用率达到 100%

java - 从有状态的 drools session 中获取事实

java - SQL 和 Java 使用 SQL 字符时出错

android - 单击 SearchView 时防止 Activity 重新加载

android - 使 Android Lollipop 中状态栏的工具栏颜色变暗

java - Android 中图像的显着性检测

JavaFX - 定义默认属性

java - 用于在 GridPane 中查找节点位置的代码如何导致 NullPointerException?

JavaFx 停止移动图像涂抹 Canvas

javascript - ExtJS:修复两个工具栏元素上的图像