Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.jfoenix.controls.JFXAutoCompletePopup;
- import com.jfoenix.controls.JFXButton;
- import com.jfoenix.controls.JFXTextField;
- import com.jfoenix.controls.events.JFXAutoCompleteEvent;
- public class MainPageController implements Initializable
- {
- @FXML
- private JFXTextField Particular_1_InputFiled;
- ArrayList ParticularName = new ArrayList();
- public void initialize(URL url, ResourceBundle rb)
- {
- dataBaseParticularName();
- }
- private void dataBaseParticularName()
- {
- try
- {
- Connection conn= DB.DbConnection.getconnection();
- String sql = "SELECT * FROM Stock";
- ResultSet rs = conn.createStatement().executeQuery(sql);
- while(rs.next())
- {
- String particularname = rs.getString("Name");
- ParticularName.add(particularname);
- }
- rs.close();
- conn.close();
- }
- catch (SQLException e)
- {
- System.err.println("Error"+e);
- }
- }
- @FXML
- private void AutoPop_KeyReleased_ParticularName(KeyEvent event)
- {
- JFXAutoCompletePopup<String> autoCompletePopup = new JFXAutoCompletePopup<>();
- autoCompletePopup.getSuggestions().addAll(ParticularName);
- autoCompletePopup.setSelectionHandler((JFXAutoCompleteEvent<String> event1) -> {
- Particular_1_InputFiled.setText(event1.getObject());
- // you can do other actions here when text completed
- });
- // filtering options
- Particular_1_InputFiled.textProperty().addListener(observable -> {
- autoCompletePopup.filter(string -> string.toLowerCase().contains(Particular_1_InputFiled.getText().toLowerCase()));
- if (autoCompletePopup.getFilteredSuggestions().isEmpty() || Particular_1_InputFiled.getText().isEmpty()) {
- autoCompletePopup.hide();
- // if you remove textField.getText.isEmpty() when text field is empty it suggests all options
- // so you can choose
- } else {
- autoCompletePopup.show(Particular_1_InputFiled);
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment