【发布时间】:2017-12-24 02:04:58
【问题描述】:
我想知道是否有人知道如何将工具栏中的图像稍微移到工具栏中的右侧,这样它就不会太靠近窗格的边缘。
这是我目前拥有的: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))(例如)。如果您真的想将其居中,请尝试将标签的最大宽度设置为Double.MAX_VALUE,并将alignment设置为CENTER(尽管我不完全确定工具栏如何管理其布局)。 -
@James_D ohhh 没有考虑 setPadding 的事情,但这已经解决了问题!我现在可以在工具栏中移动它了,谢谢!