Java Code Examples for javafx.scene.control.TextField.setOnKeyPressed()

The following are Jave code examples for showing how to use setOnKeyPressed() of the javafx.scene.control.TextField class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Squid   File: IsotopesManagerController.java   Source Code and License Vote up 8 votes
private void createTextField() {
    textField = new TextField(getString());
    textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
    textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> arg0,
                Boolean arg1, Boolean arg2) {
            if (!arg2) {
                commitEdit(textField.getText());
            }
        }
    });

    textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
        @Override
        public void handle(KeyEvent ke) {
            KeyCode kc = ke.getCode();
            if ((kc.equals(KeyCode.ENTER) || kc.equals(KeyCode.UP) || kc.equals(KeyCode.DOWN) || kc.equals(KeyCode.LEFT) || kc.equals(KeyCode.RIGHT))) {
                commitEdit(textField.getText());
            }
        }
    });
}
 
Example 2
Project: uPMT   File: InterviewTreeViewController.java   Source Code and License Vote up 6 votes
public void renameInter(){
	renameInterview.setDisable(true);
	TextField textField = new TextField();
	textField.setText(interview.getNom());
	textField.setMaxWidth(100);
	textField.requestFocus();
	textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
		 @Override
		    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
		    {
		        if (!newPropertyValue)
		        {
		        	nomEntretien.setText(textField.getText());
		        	interview.setNom(textField.getText());
					interviewPane.setLeft(nomEntretien);
					renameInterview.setDisable(false);
		        }
		    }
	});
	textField.setOnKeyPressed(new EventHandler<KeyEvent>() {

		@Override
		public void handle(KeyEvent event) {
			if(event.getCode() == KeyCode.ENTER){
				nomEntretien.setText(textField.getText());
				interview.setNom(textField.getText());
				interviewPane.setLeft(nomEntretien);
				renameInterview.setDisable(true);
			}
			if(event.getCode() == KeyCode.ESCAPE){
				interviewPane.setLeft(nomEntretien);
				renameInterview.setDisable(true);
			}
		}
	});
	interviewPane.setLeft(textField);
	Platform.runLater(()->textField.requestFocus());
	Platform.runLater(()->textField.selectAll());
	
}
 
Example 3
Project: FlashLib   File: VisionEditorWindow.java   Source Code and License Vote up 6 votes
ParamField(String name, Property<T> prop, Class<T> genericType) {
	field = new TextField();
	Label lbl = new Label(name);
	valueProperty = prop;
	this.genericType = genericType;
	
	lastValue = prop.getValue();
	field.setText(lastValue.toString());
	field.setOnKeyPressed(e ->{
		if(e.getCode() == KeyCode.ENTER)
			newValue();
	});
	field.focusedProperty().addListener((obs, o, n)->{
		if(o.booleanValue() && !n.booleanValue())
			newValue();
	});
	
	root = new VBox();
	root.getChildren().addAll(lbl, field);
}
 
Example 4
Project: FlashLib   File: MainWindow.java   Source Code and License Vote up 6 votes
public VisionControl() {
	slider = new Slider();
	slider.setMin(0.0);
	slider.setMax(255.0);
	slider.setValue(0.0);
	slider.setMaxWidth(350.0);
	slider.setDisable(true);
	
	inputText = new TextField();
	inputText.setText("0");
	inputText.setMaxWidth(50.0);
	inputText.setOnKeyPressed((e)->{
		if(e.getCode() == KeyCode.ENTER){
			setTextFromField();
		}
	});
	inputText.focusedProperty().addListener((obs, o, n)->{
		if(!n.booleanValue()){
			inputText.setText(String.valueOf((int)slider.getValue()));
		}
	});
	
	slider.valueProperty().addListener((obs, o, n)->{
		inputText.setText(String.valueOf((int)slider.getValue()));
	});
	
	nameLabel = new Label("");
	
	HBox top = new HBox();
	top.setSpacing(5.0);
	top.getChildren().addAll(nameLabel, inputText);
	
	VBox all = new VBox();
	all.setSpacing(10.0);
	all.getChildren().addAll(top, slider);
	root = all;
}
 
Example 5
Project: CDN-FX-2.2   File: TDATableFilter.java   Source Code and License Vote up 6 votes
public static SortedList<Ticket> createTableFilter(TextField textSearch, ListView listView){

        if(isPrepared)
            return new SortedList<>(filteredTickets);

        textSearch.setOnKeyPressed((KeyEvent ke) ->{
            if(ke.getCode().equals(KeyCode.ENTER)){
                text = textSearch.getText().toLowerCase();
                filterTickets();
            }
        });

        //Listview
        listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                categoryText = newValue.split(" ")[0];
                if(categoryText.equals("DownloadPlayChild"))
                    categoryText = "DLP";
                filterTickets();
            }
        });

        isPrepared = true;
        return new SortedList<>(filteredTickets);
    }
 
Example 6
Project: CDN-FX-2.2   File: TMTableFilter.java   Source Code and License Vote up 6 votes
public static SortedList<Ticket> createTableFilter(TextField textSearch, ListView listView){

        if(isPrepared)
            return new SortedList<>(filteredTickets);

        textSearch.setOnKeyPressed((KeyEvent ke) ->{
            if(ke.getCode().equals(KeyCode.ENTER)){
                text = textSearch.getText();
                filterTickets();
            }
        });

        //Listview
        listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                categoryText = newValue.split(" ")[0];
                if(categoryText.equals("DownloadPlayChild"))
                    categoryText = "DLP";
                filterTickets();
            }
        });

        isPrepared = true;
        return new SortedList<>(filteredTickets);
    }
 
Example 7
Project: Conan   File: ViewUtil.java   Source Code and License Vote up 5 votes
public static void consumeKeys(TextField tf) {
    tf.setOnKeyPressed(key -> {
        if (ctrlY.match(key) || ctrlZ.match(key)) {
            key.consume();
        }
    });
}
 
Example 8
Project: marathonv5   File: TextAreaReadline.java   Source Code and License Vote up 5 votes
public TextAreaReadline(TextField text, TextArea output, final String message) {
    this.area = text;
    this.output = output;
    readline = new Readline();
    inputJoin.send(Channel.EMPTY, null);
    text.setOnKeyPressed(this);
    if (message != null) {
        append(message, promptStyle);
    }
}
 
Example 9
Project: uPMT   File: MomentExpVBox.java   Source Code and License Vote up 5 votes
private void editNameMode() {
	TextField t = new TextField();
	t.setMaxWidth(180);
	t.setText(moment.getNom());
	t.requestFocus();
	
	ChangeListener<Boolean>	 listener = new ChangeListener<Boolean>() {
		 @Override
		    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
		    {
		        if (!newPropertyValue)
		        {
		        	RenameMomentCommand cmd = new RenameMomentCommand(nameController,moment.getNom(),t.getText());
					cmd.execute();
					UndoCollector.INSTANCE.add(cmd);
					borderPaneLabel.setCenter(label);
					t.focusedProperty().removeListener(this);
		        }
		    }
	};
	t.setOnKeyPressed(new EventHandler<KeyEvent>() {

		@Override
		public void handle(KeyEvent event) {
			if(event.getCode() == KeyCode.ENTER){
				t.setText(t.getText());
				borderPaneLabel.setCenter(label);
			}
			if(event.getCode() == KeyCode.ESCAPE){
				borderPaneLabel.setCenter(label);
			}
		}
	});
	t.focusedProperty().addListener(listener);
	Platform.runLater(()->t.requestFocus());
	Platform.runLater(()->t.selectAll());
	borderPaneLabel.setCenter(t);
}
 
Example 10
Project: uPMT   File: MainViewController.java   Source Code and License Vote up 4 votes
private void editNameMode() {
		TextField t = new TextField();
		t.setText(main.getCurrentMoment().getMoment().getNom());
		t.requestFocus();
		Platform.runLater(new Runnable() {
            @Override
            public void run() {
            	//Le Textfield demande le Focus
            	t.requestFocus();
            	//Si le text n'est pas vide, on selectionne tout.
            	if(!t.getText().isEmpty())
            		t.selectAll();
            }
        });
		
		ChangeListener<Boolean>	 listener = new ChangeListener<Boolean>() {
			 @Override
			    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
			    {
			        if (!newPropertyValue)
			        {
			        	RenameMomentCommand cmd = new RenameMomentCommand(main.getCurrentMoment().getMomentNameController(),
								main.getCurrentMoment().getMoment().getNom(),t.getText());
						cmd.execute();
						UndoCollector.INSTANCE.add(cmd);
						vBoxLabel.getChildren().remove(t);
						vBoxLabel.getChildren().add(0,nomMoment);
						t.focusedProperty().removeListener(this);
			        }
			    }
		};
		t.setOnKeyPressed(new EventHandler<KeyEvent>() {

			@Override
			public void handle(KeyEvent event) {
				if(event.getCode() == KeyCode.ENTER){
					t.setText(t.getText());
					vBoxLabel.getChildren().remove(t);
				}
				if(event.getCode() == KeyCode.ESCAPE){
					vBoxLabel.getChildren().remove(t);
					vBoxLabel.getChildren().add(0, nomMoment);
				}
			}
		});
		t.focusedProperty().addListener(listener);
//		Platform.runLater(()->t.requestFocus());
//		Platform.runLater(()->t.selectAll());
		vBoxLabel.getChildren().add(0, t);
		vBoxLabel.getChildren().remove(nomMoment);
	}