拦截JavaFx HTMLEditor上的粘贴事件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了拦截JavaFx HTMLEditor上的粘贴事件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2149字,纯文字阅读大概需要4分钟。
内容图文
您好我想知道如何拦截JavaFX HTMLEditor中的粘贴事件.
解决方法:
你不能. HTMLEditor在内部使用WebPage.基本上在粘贴事件期间,它通过发送“粘贴”命令
private boolean executeCommand(String command, String value) {
return webPage.executeCommand(command, value);
}
然后一个
twkExecuteCommand(getPage(), command, value);
但是,您可以拦截隐式调用粘贴事件的所有内容,例如按钮单击或CTRL V组合键,并根据您要执行的操作消耗事件.
例:
public class HTMLEditorSample extends Application {
@Override
public void start(Stage stage) {
final HTMLEditor htmlEditor = new HTMLEditor();
Scene scene = new Scene(htmlEditor, 800, 600);
stage.setScene(scene);
stage.show();
Button button = (Button) htmlEditor.lookup(".html-editor-paste");
button.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
System.out.println("paste pressed");
// e.consume();
});
htmlEditor.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
if( e.isControlDown() && e.getCode() == KeyCode.V) {
System.out.println( "CTRL+V pressed");
// e.consume();
}
});
}
public static void main(String[] args) {
launch(args);
}
}
至于你的other question只将纯文本粘贴到html编辑器,你可以这样做:
public class HTMLEditorSample extends Application {
@Override
public void start(Stage stage) {
final HTMLEditor htmlEditor = new HTMLEditor();
Scene scene = new Scene(htmlEditor, 800, 600);
stage.setScene(scene);
stage.show();
Button button = (Button) htmlEditor.lookup(".html-editor-paste");
button.addEventFilter(MouseEvent.MOUSE_PRESSED, e -> {
modifyClipboard();
});
htmlEditor.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
if( e.isControlDown() && e.getCode() == KeyCode.V) {
modifyClipboard();
}
});
}
private void modifyClipboard() {
Clipboard clipboard = Clipboard.getSystemClipboard();
String plainText = clipboard.getString();
ClipboardContent content = new ClipboardContent();
content.putString(plainText);
clipboard.setContent(content);
}
public static void main(String[] args) {
launch(args);
}
}
这是一种解决方法而且难看,因为除非用户愿意,否则不应修改剪贴板内容,但它可以正常工作.另一方面,可以在粘贴操作之后将剪贴板内容恢复回其原始状态.
编辑:
以下是访问上下文菜单的方法,例如: G.禁用它:
WebView webView = (WebView) htmlEditor.lookup(".web-view");
webView.setContextMenuEnabled(false);
内容总结
以上是互联网集市为您收集整理的拦截JavaFx HTMLEditor上的粘贴事件全部内容,希望文章能够帮你解决拦截JavaFx HTMLEditor上的粘贴事件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。