gpt4 book ai didi

JavaFX - 处理重复的子错误 - RadioButtons

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

我有三个单选按钮,我希望根据我单击的复选框上传我的 GUI。

我引用过本指南:http://docs.oracle.com/javafx/2/ui_controls/radio-button.htm这似乎非常适合我的需求。但是,尽管导入了正确的库,它仍无法识别类型。我决定编写自己的小代码。

我们有水平盒子和垂直盒子。我已将标签和文本元素添加到一个水平框中(用 hb、hb1、hb2.. 表示),并将它们全部放在一个垂直框中。

这是我的单选按钮事件监听器的代码:

test1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {

try{
//Remove all existing children
vb.getChildren().removeAll(hb,hb2,hb3,hb4,hb5);
log("Cleared");
} catch(Exception e)
{
log(e.getMessage());
}
try{
//Add email and email text into a horizontal box
hb.getChildren().addAll(email, email_text);
hb.setSpacing(10);
//Added the box to the vertical box
vb.getChildren().add(hb);

log("Added the email input box");
}
catch(Exception e){
log(e.getMessage());
}
}
});

声明:

final ToggleGroup group = new ToggleGroup();

final RadioButton test1 = new RadioButton("Test 1");
test1.setToggleGroup(group);
grid.add(test1, 0, 1);

final RadioButton test2 = new RadioButton("Test 2");
test2.setToggleGroup(group);
grid.add(test2, 0, 2);

final VBox vb = new VBox(10); // main container
final HBox hb = new HBox(); // Email , Email Text
final HBox hb2 = new HBox(); // Corporate , Corporate Name

我收到错误:子项:添加了重复的子项:parent = HBox@359889fd。我对此做了一些研究:java.lang.IllegalArgumentException: Children: duplicate children added: parent = VBox@872be7 。老实说,即使我们都在解决同一个问题,我也很难得到他的代码。

我的主要问题:如果我删除开头的所有元素,为什么会出现重复错误?

也许,我的代码可能完全错误并且毫无意义。您推荐其他方法吗?

最佳答案

主要问题是我删除了 vb 框,但没有删除 hb 的内容。然而,我正在添加 hb。我也应该从 hb 中删除。

关于JavaFX - 处理重复的子错误 - RadioButtons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26386028/

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