如何在 JavaFx 的工具栏中移动图像
How to move image in ToolBar in JavaFx
我想知道是否有人知道如何将工具栏中的图像稍微向右移动,使其不那么靠近窗格的边缘。
这是我目前拥有的:https://i.stack.imgur.com/vZnzX.png
我希望它只向右移动几个像素,以便它位于工具栏的中央。
我目前正在使用分配给标签的图像视图在工具栏中显示图像
感谢您的帮助
这是我的代码:
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));
我想知道是否有人知道如何将工具栏中的图像稍微向右移动,使其不那么靠近窗格的边缘。
这是我目前拥有的:https://i.stack.imgur.com/vZnzX.png
我希望它只向右移动几个像素,以便它位于工具栏的中央。
我目前正在使用分配给标签的图像视图在工具栏中显示图像
感谢您的帮助
这是我的代码:
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));