尝试使用JavaFx制作字典。 这是我的Controller类 -
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());
}
}
这是我加载数据的模型类 -
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;
}
}
现在我正在尝试将searchField
与加载的MeaningList
绑定,并将绑定的数据填充到ovidhanTable
。
我怎么能这样做?