0

I have used Combobox in editable mode and i have used filtered list to filter the list as the text change in the editor. The filtering works as i type the data in the editor. The problem occurs when i select member from the drop down list, the selected value disappear as soon i select a member from the drop down list.

When i run the same code in jdk 8 it is working but in jdk 19 the problem arises.

I have uploaded both the vodeos.

  1. Program run with jdk 8
  2. Program run with jdk 19 and javafx 19

The code is displayed as follows

    public TextField _unit_type;
    public TextField _symbol;
    public TextField _formal_name;
    public ComboBox<UnitQuantityCode> _unit_quantity_code;
    public TextField _number_of_decimal_places;

    private UnitSecondary unitSecondary;
    private UnitCodeDao unitCodeDao;
    private ObservableList<UnitQuantityCode> codes;
    private FilteredList<UnitQuantityCode> filteredList;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        unitCodeDao = new UnitCodeDao();
        unitSecondary = new UnitSecondary();
        codes = FXCollections.observableArrayList();
        filteredList = new FilteredList<>(codes);
        codes.setAll(unitCodeDao.getAllUqc());
        _unit_quantity_code.setItems(filteredList);

        _unit_quantity_code.setCellFactory(new CodeCellFactory());
        _unit_quantity_code.setConverter(new CodeStringConverter());
        _unit_quantity_code.getEditor().focusedProperty().addListener(new UnitComboFocusListener());
        _unit_quantity_code.getEditor().textProperty().addListener(new TextChangeListener());
    }

    private class CodeCellFactory implements Callback<ListView<UnitQuantityCode>, ListCell<UnitQuantityCode>>{
        @Override
        public ListCell<UnitQuantityCode> call(ListView<UnitQuantityCode> unitQuantityCodeListView) {
            return new CodeCell();
        }
    }

    private class CodeCell extends ListCell<UnitQuantityCode>{
        @Override
        protected void updateItem(UnitQuantityCode unitQuantityCode, boolean b) {
            super.updateItem(unitQuantityCode, b);
            if (unitQuantityCode == null || b){
                setGraphic(null);
                setText(null);
            }else {
                setGraphic(null);
                setText(unitQuantityCode.getCode());
            }
        }
    }

    private class CodeStringConverter extends StringConverter<UnitQuantityCode>{
        private UnitQuantityCode u;
        @Override
        public String toString(UnitQuantityCode unitQuantityCode) {
            if (unitQuantityCode == null)
                return null;
            u = unitQuantityCode;
            return unitQuantityCode.getCode();
        }

        @Override
        public UnitQuantityCode fromString(String s) {
            return u;
        }
    }

    private class UnitComboFocusListener implements ChangeListener<Boolean>{
        @Override
        public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean t1) {
            if (t1){
                _unit_quantity_code.show();
            }else{
                _unit_quantity_code.hide();
            }
        }
    }

    private class TextChangeListener implements ChangeListener<String>{
        @Override
        public void changed(ObservableValue<? extends String> observableValue, String s, String t1) {
            if (!t1.equals("")){
                Platform.runLater(()->filteredList.setPredicate(
                        t->t.getCode().toLowerCase().contains(t1.toLowerCase())));
            }else{
                Platform.runLater(()->filteredList.setPredicate(null));
            }
        }
    }

Kindly provide a solution.

Ranjit Vamadevan
  • 514
  • 5
  • 21

0 Answers0