Aman Gupta
Aman Gupta

Reputation: 21

Disable keyboard shortcuts in JavaFx

is it possible, to disable Ctrl+V shortcut in my JavaFx application ? its like in the textfields, user will not be able to copy text from somewhere and paste it using Ctrl+V.

here's my controller class :

package application;

import com.jfoenix.controls.JFXTextField;
import javafx.fxml.FXML;

public class Controller {

    @FXML
    private JFXTextField t1 = new JFXTextField() {
        @Override
        public void paste() {
            //do something to stop paste
        }
    };
}

Upvotes: 0

Views: 2079

Answers (1)

Ahmed Emad
Ahmed Emad

Reputation: 674

You can do so by overriding the paste method and remove the line

super.paste();

it will do nothing when user try to paste

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {

    public static void main(String[] args){
        launch(args);
    }

    @Override
    public void start(Stage stage){

        TextField textField = new TextField(){
            @Override
            public void paste() {

            }
        };
        Scene scene = new Scene(new StackPane(textField));
        stage.setScene(scene);
        stage.show();
    }

}

Upvotes: 1

Related Questions