有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

基于键盘的java Make javafx choicebox选择项

根据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 lettersSelected 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;
}

共 (0) 个答案