gpt4 book ai didi

java - javafx 中按钮的切换组

转载 作者:行者123 更新时间:2023-12-01 09:19:05 27 4
gpt4 key购买 nike

我有以下代码,它是 javafx 中的一组按钮:

ToggleGroup groupLevelQ = new ToggleGroup();

class MyLevelButton extends ToggleButton {
public MyLevelButton(String name) {
super(name);
setPrefWidth(50.0);
setPrefHeight(50.0);
setStyle("-fx-font: 20 cornerstone; -fx-base: #17499F;");
setToggleGroup(groupLevelQ);
}
}

oneLevelButton = new MyLevelButton("1");
twoLevelButton = new MyLevelButton("2");
threeLevelButton = new MyLevelButton("3");
fourLevelButton = new MyLevelButton("4");
fiveLevelButton = new MyLevelButton("5");
sixLevelButton = new MyLevelButton("6");
sevenLevelButton = new MyLevelButton("7");
eightLevelButton = new MyLevelButton("8");
nineLevelButton = new MyLevelButton("9");

oneLevelButton.setUserData("1");
twoLevelButton.setUserData("2");
threeLevelButton.setUserData("3");
fourLevelButton.setUserData("4");
fiveLevelButton.setUserData("5");
sixLevelButton.setUserData("6");
sevenLevelButton.setUserData("7");
eightLevelButton.setUserData("8");
nineLevelButton.setUserData("9");

groupLevelQ.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
if (new_toggle != null) {
textLevelQ = (String) groupLevelQ.getSelectedToggle().getUserData();
}

}
});

addQButtonPane.add(oneLevelButton, 1, 9);
addQButtonPane.add(twoLevelButton, 2, 9);
addQButtonPane.add(threeLevelButton, 3, 9);
addQButtonPane.add(fourLevelButton, 4, 9);
addQButtonPane.add(fiveLevelButton, 5, 9);
addQButtonPane.add(sixLevelButton, 6, 9);
addQButtonPane.add(sevenLevelButton, 7, 9);
addQButtonPane.add(eightLevelButton, 8, 9);
addQButtonPane.add(nineLevelButton, 9, 9);

事实上,我正在创建按钮并将它们添加到 GridPane 中。我想弄清楚如何定义按钮之间的距离。基本上,就像他们现在一样,他们有一个默认距离,我想改变它。

编辑:

addQButtonPane = new GridPane();
addQButtonPane.setHgap(10);
addQButtonPane.setVgap(10);
addQButtonPane.setPadding(new Insets(0, 50, 0, 50));
addQButtonPane.setStyle("-fx-background-color: #95CBE5;");

这就是我的网格 Pane 的格式化方式。但我仍然想仅针对提到的特定按钮更改此格式。

编辑2:

enter image description here

最佳答案

也许通过放置 HBox 可以更好地实现您想要实现的布局类型。 es 包含选项和 Text VBox 内的元素.

但是,如果您正在寻找一种“将按钮从通常的布局中取出”的方法,您可以简单地将它们放在 HBox 中。使用columnSpan涵盖所有剩余的列:

double buttonDistance = ...
int gridPaneColumnCount = ...
HBox buttonBox = new HBox(buttonDistance,
oneLevelButton,
twoLevelButton,
threeLevelButton,
fourLevelButton,
fiveLevelButton,
sixLevelButton,
sevenLevelButton,
eightLevelButton,
nineLevelButton);

addQButtonPane.add(buttonBox, 1, 9, gridPaneColumnCount-1, 1);

关于java - javafx 中按钮的切换组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40287256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com