2

Trying to make a dictionary using JavaFx. Here is my Controller class-

public class MainUIController implements Initializable {

    DatabaseManager db=new DatabaseManager();
    ObservableList<OvidhanMeaning> MeaningList;

    @FXML
    private TextField searchField;

    @FXML
    private ImageView searchIcon;

    @FXML
    private ImageView aboutIcon;

    @FXML
    private TableView<OvidhanMeaning> ovidhanTable;

    @FXML
    private TableColumn<OvidhanMeaning, String> englishCol;

    @FXML
    private TableColumn<OvidhanMeaning, String> banglaCol;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        Image search = new Image(getClass().getResource("/images/search.png").toString(), true);
        Image about = new Image(getClass().getResource("/images/about.png").toString(), true);
        //Font bnFont = Font.loadFont(getClass().getResource("/fonts/Siyamrupali.ttf").toExternalForm(), 12);
        Font bnFont = Font.loadFont(getClass().getResourceAsStream("/fonts/Siyamrupali.ttf"), 12);

        searchIcon.setImage(search);
        aboutIcon.setImage(about);

        db.Connect("jdbc:sqlite::resource:ankurdb/bn_words.db");
        ResultSet rs = db.GetResult("select en_word,bn_word from words");
        MeaningList=FXCollections.observableArrayList();
        try {
            while(rs.next())
            {
                String enword = rs.getString("en_word");
                String bnword = rs.getString("bn_word");

                MeaningList.add(new OvidhanMeaning(enword,bnword));

                englishCol.setCellValueFactory(new PropertyValueFactory<OvidhanMeaning, String>("enword"));
                banglaCol.setCellValueFactory(new PropertyValueFactory<OvidhanMeaning, String>("bnword"));
                ovidhanTable.setItems(MeaningList);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        System.out.println(MeaningList.size());

    }
}

And here is my model class in which I loaded the data-

public class OvidhanMeaning {
    private SimpleStringProperty enword;
    private SimpleStringProperty bnword;

    public OvidhanMeaning(String enword, String bnword) {
        this.enword = new SimpleStringProperty(enword);
        this.bnword = new SimpleStringProperty(bnword);
    }

    public String getenword() {
        return enword.get();
    }

    public SimpleStringProperty enwordProperty() {
        return enword;
    }

    public String getbnword() {
        return bnword.get();
    }

    public SimpleStringProperty bnwordProperty() {
        return bnword;
    }
}

Now I'm trying to bind the searchField with the loaded MeaningList and populate the binded data into ovidhanTable. How can I do this?

Abdullah Al Imran
  • 1,166
  • 2
  • 17
  • 30
  • 1
    You can use `FilteredList`. Have a look [here](http://stackoverflow.com/questions/28448851/how-to-use-javafx-filteredlist-in-a-listview) for sample usage – Itai Jun 24 '16 at 19:45

0 Answers0