Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- java.util.ArrayList;
- import java.util.List;
- import org.controlsfx.control.textfield.TextFields;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.event.EventType;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.control.ComboBox;
- import javafx.scene.input.KeyCode;
- import javafx.scene.input.KeyEvent;
- import javafx.scene.input.MouseEvent;
- import javafx.stage.Stage;
- public class TestAutoTextSearch_bkp extends Application {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- launch();
- }
- @Override
- public void start(Stage primaryStage) throws Exception {
- List<String> countries = new ArrayList<>();
- countries.add("Arial");
- countries.add("Arial Black");
- countries.add("Arial Narrow");
- ComboBox<String> comboBox = new ComboBox();
- comboBox.getItems().addAll(countries);
- ComboBox<String> comboBox1 = new ComboBox();
- comboBox.setEditable(true);
- comboBox.setMaxWidth(Double.MAX_VALUE);
- comboBox.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- //Tried dispose method here but dint worked[![enter image description here][1]][1]
- }
- });
- comboBox.getEditor().setOnKeyPressed(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent ke) {
- KeyCode kc = ke.getCode();
- System.out.println("Inside Key Press");
- if ((kc.isLetterKey())||kc.isArrowKey()||kc.equals(KeyCode.BACK_SPACE)) {
- TextFields.bindAutoCompletion(comboBox.getEditor(), comboBox.getItems());
- }}
- });
- Group root = new Group();
- root.getChildren().add(comboBox);
- Scene scene = new Scene(root);
- primaryStage.setScene(scene);
- primaryStage.show();
- comboBox.setMinWidth(comboBox.getWidth());
- comboBox.setPrefWidth(comboBox.getWidth());
- }
- }
Add Comment
Please, Sign In to add comment