0
これで何も見つかりませんでした。そのため、簡単な質問を投稿したかったのです。私は拡張時のフィールドの組み合わせを表示するカスタムコンボボックスを作成したいと思います。下のコードは正しく私のリストを表示し、キーボードの矢印に反応しますが、ドロップダウンから矢印を選択すると、リストは選択のためのマウスクリックに反応しません。カスタムコンボボックスはマウスで選択しませんか?
[編集]また、私は先にタイプすることもできません。
私は何が欠けているのか分かりません。
public class JavaFXApplication7 extends Application {
@Override
public void start(Stage primaryStage) {
ComboBox<Person> cb = new ComboBox();
cb.setCellFactory(column -> new ListCell<Person>() {
private HBox graphic = new HBox();
private Label label1 = new Label() ;
private Label label2 = new Label(" || ");
private Label label3 = new Label();
{
graphic.getChildren().addAll(label1, label2, label3);
}
@Override
public void updateItem(Person person, boolean empty) {
if (person == null || empty) {
setGraphic(null);
} else {
label1.setText(person.firstName.get());
label3.setText(person.email.get());
setGraphic(graphic);
}
}
});
ObservableList<Person> items = FXCollections.observableArrayList();
Person p = new Person();
p.email.set("[email protected]");
p.firstName.set("Tony");
p.lastName.set("Stark");
p.phone.set("(555) 555-1212");
items.add(p);
Person p2 = new Person();
p2.email.set("[email protected]");
p2.firstName.set("Bruce");
p2.lastName.set("Wayne");
p2.phone.set("(444) 444-1212");
items.add(p2);
cb.setItems(items);
StackPane root = new StackPane();
root.getChildren().add(cb);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
public class Person {
StringProperty firstName = new SimpleStringProperty();
StringProperty lastName = new SimpleStringProperty();
StringProperty phone = new SimpleStringProperty();
StringProperty email = new SimpleStringProperty();
@Override
public String toString() {
return firstName.get() + " " + lastName.get();
}
}
}