Guest User

Untitled

a guest
Feb 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. import org.controlsfx.control.textfield.TextFields;
  5.  
  6. import javafx.application.Application;
  7. import javafx.event.ActionEvent;
  8. import javafx.event.EventHandler;
  9. import javafx.event.EventType;
  10. import javafx.scene.Group;
  11. import javafx.scene.Scene;
  12. import javafx.scene.control.ComboBox;
  13. import javafx.scene.input.KeyCode;
  14. import javafx.scene.input.KeyEvent;
  15. import javafx.scene.input.MouseEvent;
  16. import javafx.stage.Stage;
  17.  
  18. public class TestAutoTextSearch_bkp extends Application {
  19.  
  20. public static void main(String[] args) {
  21. // TODO Auto-generated method stub
  22. launch();
  23.  
  24. }
  25.  
  26. @Override
  27. public void start(Stage primaryStage) throws Exception {
  28. List<String> countries = new ArrayList<>();
  29. countries.add("Arial");
  30. countries.add("Arial Black");
  31. countries.add("Arial Narrow");
  32.  
  33.  
  34. ComboBox<String> comboBox = new ComboBox();
  35. comboBox.getItems().addAll(countries);
  36. ComboBox<String> comboBox1 = new ComboBox();
  37.  
  38. comboBox.setEditable(true);
  39. comboBox.setMaxWidth(Double.MAX_VALUE);
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. comboBox.setOnAction(new EventHandler<ActionEvent>() {
  47. @Override
  48. public void handle(ActionEvent event) {
  49. //Tried dispose method here but dint worked[![enter image description here][1]][1]
  50.  
  51.  
  52. }
  53. });
  54.  
  55. comboBox.getEditor().setOnKeyPressed(new EventHandler<KeyEvent>() {
  56. @Override
  57. public void handle(KeyEvent ke) {
  58. KeyCode kc = ke.getCode();
  59. System.out.println("Inside Key Press");
  60. if ((kc.isLetterKey())||kc.isArrowKey()||kc.equals(KeyCode.BACK_SPACE)) {
  61. TextFields.bindAutoCompletion(comboBox.getEditor(), comboBox.getItems());
  62.  
  63.  
  64. }}
  65. });
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. Group root = new Group();
  75. root.getChildren().add(comboBox);
  76.  
  77. Scene scene = new Scene(root);
  78. primaryStage.setScene(scene);
  79. primaryStage.show();
  80.  
  81. comboBox.setMinWidth(comboBox.getWidth());
  82. comboBox.setPrefWidth(comboBox.getWidth());
  83.  
  84. }
  85.  
  86. }
Add Comment
Please, Sign In to add comment