0

是否可以在我的 JavaFx 应用程序中禁用 Ctrl+V 快捷方式?就像在文本字段中一样,用户将无法从某处复制文本并使用 Ctrl+V 粘贴它。

这是我的控制器类:

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
        }
    };
}
4

1 回答 1

1

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();
    }

}
于 2018-07-21T15:26:15.180 回答