I have to create an auto fill ComboBox
based on user input.
My code goes like this:
public class JavaFXApplication1 extends Application {
@Override
public void start(Stage primaryStage) {
ComboBox<String> combo = new ComboBox<>();
ObservableList<String> list = FXCollections.observableArrayList();
list.add("A");
list.add("AND");
list.add("ANDR");
list.add("ANDRE");
list.add("B");
list.add("BP");
list.add("BPO");
combo.setItems(list);
new AutoCompleteComboBoxListener(combo);
StackPane root = new StackPane();
root.getChildren().add(combo);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
the AutoCompleteComboBoxListener
is taken from this answer.
With this autocomplete works fine. I faced a problem in list size,
Run the application and click on the ComboBox
drop down to see popup size.
- Type ANDRE in the combo box(which will show ANDRE option in popup).Now delete all characters.(by backspace)
- Now the populated list shrinked to one entry size with scroll bar.
- Click on the combo box drop down again to get the full size list.
How can I make the list size according to content?