我试图将按钮添加到包含在VBox中的BoarderPane中,但它们似乎是重叠的。
我的fxml文件中的VBox片段是
<VBox fx:id="leftPlayerPlayArea" alignment="CENTER" minHeight="0.0" minWidth="0.0" prefWidth="120.0" BorderPane.alignment="CENTER_LEFT">
<BorderPane.margin>
<Insets left="30.0" />
</BorderPane.margin>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>当我在控制器类中添加按钮时,这些按钮会很好地添加到我的Hbox中,但是它们不会很好地添加到我的Vbox中。以下是图片:
VBox

HBox

最后,我是如何创建这些按钮的:
private Button playerPromptButtonCreator(String buttonText, EventHandler<ActionEvent> event, int id) {
Button button = createBtn(buttonText);
button.setMinWidth(BTN_MAX_WIDTH);
button.setMinHeight(BTN_MAX_HEIGHT);
button.setOnAction(event);
if (playerPositions.get(id) == PlayerPosition.LEFT){
button.setRotate(90);
}
if (playerPositions.get(id) == PlayerPosition.RIGHT)
{
button.setRotate(270);
}
Platform.runLater(new Runnable() { //and create the button if it doesnt exist if it doesnt
@Override
public void run() {
//THIS IS MY LINE
playerPlayAreas.get(id).add(button);
}
});
return button;
}我也尝试了setSpacing()属性作为我的VBox,但这没有效果。
发布于 2018-03-02 09:48:19
要确定父布局中节点的大小,JavaFX使用未转换的节点的边界,也就是说,它不考虑旋转,而是使用以宽度表示为高度的大小。
您可以通过将Button包装到Group中来修复这个问题,但是这需要您编辑方法的签名或修改调用方法:
Button button1 = new Button("Yes");
Button button2 = new Button("No");
button1.setRotate(90);
button2.setRotate(90);
VBox layout = new VBox(new Group(button1), new Group(button2));https://stackoverflow.com/questions/49062633
复制相似问题