I want to make this TextField have suggestions feature just like in Lucene. I've searched all the web and I just find it for ComboBox.
TextField instNameTxtFld = instNameTxtFld();
private TextField instNameTxtFld() {
TextField txtFld = new TextField();
txtFld.setPrefSize(600, 75);
return txtFld;
}
The reason that I can't use the method for ComboBox is because I can't input the value to database below if I use ComboBox.
private void goNext() {
if (nameTxtFld.getText() == null || nameTxtFld.getText().trim().isEmpty()
|| instNameTxtFld.getText()== null || instNameTxtFld.getText().trim().isEmpty()
|| addTxtArea.getText() == null || addTxtArea.getText().trim().isEmpty()) {
alertDialog.showAndWait();
} else {
String satu = idNumTxtFld.getText();
String dua = nameTxtFld.getText();
String tiga = addTxtArea.getText();
String empat = instNameTxtFld.getText();
int delapan = idType.getSelectionModel().getSelectedIndex();
String sembilan = timeStamp.getText();
try {
KonekDB.createConnection();
Statement st = KonekDB.conn.createStatement();
String sql = "INSERT INTO privateguest"
+ "(idNumber, name, address, institution, idType, startTime) "
+ "VALUES "
+ "('" + satu + "','" + dua + "','" + tiga + "','" + empat + "','" + delapan + "','" + sembilan + "')";
System.out.println(sql);
st.executeUpdate(sql);
} catch (SQLException ex) {
System.out.println(satu + " " + dua + " " + tiga + " " + empat + " " + delapan + " " + sembilan);
System.out.println("SQL Exception (next)");
ex.printStackTrace();
}
Frame3Private frame3 = new Frame3Private(english);
this.getScene().setRoot(frame3);
}
}
Please help me to make the most simple code for doing TextField suggestions/ auto-complete.
Here is my solution based on This.
You must extends from "TextField" instead of "TextFieldWithLengthLimit" and delete constructor with "Length limit".
I use static methods to work with Styles. It's used here to "highlight" entered text inside suggestion results. Here is the code of methos from this class:
You may add this "AutocompletionlTextField" in FXML (dont forget about "imports") or inside constructor. To set "suggestions" list on use "entries" getter:
It seems like that in my application:
Hope it helps.
You can use ControlsFX --> maven
Solution:
Here is my solution - a complete method only with a ComboBox parameter:
There is another solution with JFoenix. Since February 2018 they added autocompletion class. This is implementation of it.
This is a bit new approach and worked fine with me. Hope it will help and thanks to JFoenix developers.