FXML - 如何在 ChoiceBox 中预选项目?

发布于 2024-12-28 20:31:46 字数 350 浏览 5 评论 0原文

FXML 的等效项是什么(cb 是一个 ChoiceBox):

cb.getSelectionModel().select(1);

我尝试了这样的方法:

<ChoiceBox SelectionModel.select="1">
....
</ChoiceBox>

以及

<ChoiceBox>
<SelectionModel select="1"/>
....
</ChoiceBox>

许多类似的变体,但这些都不起作用

What is the FXML equivalent for this (cb is a ChoiceBox):

cb.getSelectionModel().select(1);

I tried something like this:

<ChoiceBox SelectionModel.select="1">
....
</ChoiceBox>

and

<ChoiceBox>
<SelectionModel select="1"/>
....
</ChoiceBox>

and a lot of similar variations, but those didn't work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2025-01-04 20:31:46

现在,您必须通过 Controller 类中的 Java 代码来完成此操作。
已提交一个待处理的增强请求来处理 FXML 中的此问题。它看起来与您在这里发布的内容非常相似。

Right now, you have to do it via Java code in the Controller class.
There is a pending enhancement request already submitted to handle this in the FXML. It looks very similar to your posting here.

噩梦成真你也成魔 2025-01-04 20:31:46

如果您使用场景生成器,请在 fxml 中尝试此操作。

<ChoiceBox fx:id="choice" layoutX="181.0" layoutY="14.0" prefHeight="25.0" prefWidth="119.0" value="item1" >
<String fx:value="item1" />
<Separator />
<String fx:value="item2" />
</ChoiceBox>

if you using scene builder then try this in fxml.

<ChoiceBox fx:id="choice" layoutX="181.0" layoutY="14.0" prefHeight="25.0" prefWidth="119.0" value="item1" >
<String fx:value="item1" />
<Separator />
<String fx:value="item2" />
</ChoiceBox>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文