[英]How to populate Combo box in Runtime?
A Combo Box has a list, based on user's selection another Combo Box has to be populated with values.组合框有一个列表,根据用户的选择,另一个组合框必须填充值。 But these values are queried from a sqlite database, later the combo box is populated.
但是这些值是从 sqlite 数据库中查询的,随后组合框被填充。
Here is some code we use to extract data from a Derby Database and add to a下面是一些我们用来从 Derby 数据库中提取数据并添加到
ListView TextArea and ComboBox ListView TextArea 和 ComboBox
ResultSet rs2 = stmnt.executeQuery("SELECT * FROM dic WHERE dicword LIKE '"+""+strS+"%"+"'ORDER BY dicword ASC" );
while (rs2.next()){
test2 = rs2.getString("dicword");
cboSelect.getItems().add(test2);
lvListView.getItems().add(test2);
txaML.appendText(test2);
txaML.appendText("\n");
}
Then here is the code for the ComboBox然后这里是 ComboBox 的代码
public void cboSelect(){
ObservableList months = FXCollections.observableArrayList();
}
@FXML
public void getSelection() throws SQLException, IOException{
if(cboSelect.getValue() != null) {
String selected = cboSelect.getValue().toString();
txtTo.setText(selected);
String testCB = txtMonitor.getText();
boolean isCAP;
char first = testCB.charAt(0);
if (Character.isUpperCase(first)) {
isCAP = true;
System.out.println("!!! first "+first);
System.out.println("!!! isCAP "+isCAP);
String M = selected;
String firstL = M.substring(0,1).toUpperCase();
String restL = M.substring(1).toLowerCase();
txtTest.setText(firstL+restL);
txtTo.setText(firstL+restL);
}
}
}
If you want to use the data from the database just put it in an ArrayList如果您想使用数据库中的数据,只需将其放入 ArrayList
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.