Wenn ich auf die Außenseite eines Kombinationsfelds (freier Speicherplatz in diesem Fenster) klicken, wird die Auswahl des Kombinationsfelds verschwinden und null
drucken.ComboBox Auswahl verloren, wenn außerhalb der Box geklickt
Dies ist innerhalb Controller-Klasse
@FXML
public ComboBox routineGridShowComboBox;
public void actionForRoutineGridShowComboBox(ActionEvent event){
System.out.println(routineGridShowComboBox.getValue());
}
public void addOptionToComboBox(){
routineGridShowComboBox.getItems().removeAll(routineGridShowComboBox.getItems());
routineGridShowComboBox.getItems().addAll("Hello","World");
}
und hier ist der FXML Code:
<ComboBox fx:id="routineGridShowComboBox" layoutX="24.0" layoutY="56.0" onAction="#actionForRoutineGridShowComboBox" onMouseClicked="#addOptionToComboBox" prefHeight="25.0" prefWidth="384.0" promptText="Choose your subject ... " />
Sie haben nicht genügend Informationen zur Verfügung gestellt. Niemand kann möglicherweise wissen, was e. G. '# addOptionToComboBox' macht, wie Ihre' ComboBox' gefüllt ist, was anderes passiert, etc. – Roland
Was Sie gepostet haben, tut nicht das, was Sie beschreiben - es löscht die Elemente und fügt sie per Mausklick wieder hinzu. Allerdings verstehe ich nicht wirklich, warum machst du das. Wenn Sie die Auswahl löschen möchten, wenn das Kombinationsfeld geöffnet wird, können Sie zum Beispiel 'routineGridShowComboBox.setOnShowing ((e) -> routineGridShowComboBox.setValue (null));' – DVarga