尝试实现“插入符浏览”使用 JavaFX 2
我正在尝试使用 JavaFX 2.0 编写一个应用程序,其中包含一个 Web 浏览器控件,该控件允许用户仅使用键盘浏览 HTML 页面上的文本和图像 - 基本上就像“插入符号浏览” ” 在 Internet Explorer 中。
目标是能够选择文本或图像位并将它们复制到变量中以进行进一步操作,而无需使用鼠标。
我在这里查看了 HTMLEditor 控件: http://docs.oracle.com/javafx/2.0/ui_controls/editor .htm#CHDBEGDD 但我不需要任何使用户界面混乱的编辑功能,文档中说:
格式化工具栏是在实现时提供的 成分。您无法切换它们的可见性。
WebView 似乎是一个合乎逻辑的选择(http://docs.oracle.com/ javafx/2.0/webview/jfxpub-webview.htm),但我不确定如何将光标移到页面上。
任何建议将不胜感激。
I'm trying to write an application using JavaFX 2.0 that includes a web browser control that allows a user to navigate through the text and images on a HTML page using only the keyboard -- basically like "caret browsing" in Internet Explorer.
The goal is to be able to select bits of text or images and copy them to a variable for further manipulation without using a mouse.
I took a look at the HTMLEditor control here:
http://docs.oracle.com/javafx/2.0/ui_controls/editor.htm#CHDBEGDD
but I don't need any editing capability cluttering up the UI, and the documentation says:
The formatting toolbars are provided in the implementation of the
component. You cannot toggle their visibility.
WebView seems like a logical choice (http://docs.oracle.com/javafx/2.0/webview/jfxpub-webview.htm), but I'm not sure how to get a cursor onto the page.
Any advice would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前的 WebView 对插入符号浏览的支持在我看来充其量是不完整的。
以下是我在运行快速测试时发现的结果:
webView.requestFocus
来让 WebView 请求焦点响应按键,但它只是对 WebView 作为一个整体进行操作,而不是对其中的各个组件进行操作Web 视图。上述限制以及我未测试的其他限制可能会使您难以完成您想要做的事情。您可以尝试使用 eventfilter,然后生成鼠标事件来启动选择和复制过程,但这对我来说听起来很困难,即便如此,目前还没有JavaFX 中用于生成鼠标事件的公共 API,只有一个不稳定的 com.sun api。
WebView 确实公开了 文档对象模型,文档为可通过 JavaScript 编写脚本。尝试使用事件过滤器捕获关键事件,侦听文档属性的更改并在适当的时间对 WebView 执行 JavaScript 以获取和设置当前选择。实施起来似乎也有点棘手。
使用当前的 WebView 控件和公共 API 尽可能多地完成任务,并在 http://javafx-jira.kenai 上记录问题.com 当您遇到缺点时。
The current WebView support for caret browsing seems patchy at best to me.
Here is what I found running a quick test:
webView.requestFocus
to have the WebView request focus for responding to key presses, but it just operates on the WebView as a whole, not individual components within the WebView.The above restrictions, and likely others I didn't test for, will likely make it hard to accomplish what you are trying to do. You could try stuff such as capturing keypress events using an eventfilter, then generating mouse events to initiate the selection and copy process, but that sounds difficult to me, and even then, there is currently no public API in JavaFX to generate mouse events, only an unstable
com.sun
api.WebView does expose a document object model, and the document is scriptable by JavaScript. Try capturing key events with an eventfilter, listening to the document property for changes and executing JavaScript against the WebView at appropriate times to get and set the current selection. This also seems a little tricky to implement well.
Accomplish as much as you can with the current WebView control and public API and log issues at http://javafx-jira.kenai.com as and when you encounter short-comings.