Guest User

Untitled

a guest
Jul 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import com.jfoenix.controls.JFXAutoCompletePopup;
  2. import com.jfoenix.controls.JFXButton;
  3. import com.jfoenix.controls.JFXTextField;
  4. import com.jfoenix.controls.events.JFXAutoCompleteEvent;
  5.  
  6. public class MainPageController implements Initializable
  7. {
  8. @FXML
  9. private JFXTextField Particular_1_InputFiled;
  10. ArrayList ParticularName = new ArrayList();
  11. public void initialize(URL url, ResourceBundle rb)
  12. {
  13. dataBaseParticularName();
  14. }
  15.  
  16.  
  17. private void dataBaseParticularName()
  18. {
  19. try
  20. {
  21. Connection conn= DB.DbConnection.getconnection();
  22. String sql = "SELECT * FROM Stock";
  23. ResultSet rs = conn.createStatement().executeQuery(sql);
  24.  
  25. while(rs.next())
  26. {
  27. String particularname = rs.getString("Name");
  28. ParticularName.add(particularname);
  29. }
  30. rs.close();
  31. conn.close();
  32. }
  33. catch (SQLException e)
  34. {
  35. System.err.println("Error"+e);
  36. }
  37. }
  38.  
  39. @FXML
  40. private void AutoPop_KeyReleased_ParticularName(KeyEvent event)
  41. {
  42. JFXAutoCompletePopup<String> autoCompletePopup = new JFXAutoCompletePopup<>();
  43. autoCompletePopup.getSuggestions().addAll(ParticularName);
  44.  
  45. autoCompletePopup.setSelectionHandler((JFXAutoCompleteEvent<String> event1) -> {
  46. Particular_1_InputFiled.setText(event1.getObject());
  47. // you can do other actions here when text completed
  48. });
  49.  
  50. // filtering options
  51. Particular_1_InputFiled.textProperty().addListener(observable -> {
  52. autoCompletePopup.filter(string -> string.toLowerCase().contains(Particular_1_InputFiled.getText().toLowerCase()));
  53. if (autoCompletePopup.getFilteredSuggestions().isEmpty() || Particular_1_InputFiled.getText().isEmpty()) {
  54. autoCompletePopup.hide();
  55. // if you remove textField.getText.isEmpty() when text field is empty it suggests all options
  56. // so you can choose
  57. } else {
  58. autoCompletePopup.show(Particular_1_InputFiled);
  59. }
  60. });
  61. }
  62. }
Add Comment
Please, Sign In to add comment