【发布时间】:2021-10-18 21:31:00
【问题描述】:
根据https://wiki.openjdk.java.net/display/OpenJFX/ChoiceBox+User+Experience+Documentation
Any Alpha-numeric Keys 应该在Jumps to the first item in the list with that letter or letters 中Selected state
但是,情况似乎根本不是这样,在选择小部件时键入似乎没有任何作用。
这是我的最小可重现示例:
package com.techniqab.testchoicebox;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.net.URL;
import java.nio.file.Paths;
public class TestchoiceboxApplication extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
URL url = Paths.get("./src/main/resources/sample.fxml").toUri().toURL();
Parent root = FXMLLoader.load(url);
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
var cb = new ChoiceBox();
cb.getItems().add("a");
cb.getItems().add("b");
((Pane) root).getChildren().add(cb);
}
public static void main(String[] args) {
launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="com.techniqab.testchoicebox.TestchoiceboxApplication"
prefHeight="400.0" prefWidth="600.0">
</AnchorPane>
module testchoicebox {
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
exports com.techniqab.testchoicebox;
opens com.techniqab.testchoicebox to javafx.graphics;
}
【问题讨论】:
-
您能否创建一个minimal reproducible example:这依赖于您尚未发布的 FXML 文件。 (而且,题外话,但你为什么要从源文件夹加载 FXML 文件?)
-
该功能标记为
Application Dependant[sic],这可能意味着它取决于您的应用程序。 -
@trashgod 我没有看到它在哪里被标记为应用程序依赖...我的应用程序依赖于此,我该如何实现它
-
@James_D 添加了其他文件...至 FXML.. 位置,因为我是 java/spring/和 javafx 的新手,这就是我想出运行最小示例的方法。
-
两个用例被标记为
Dependant——注意拼写错误。对于很长的列表,也许是某种Pagination控件?