JEditorPane、JScrollPane 和辅助功能
我有一个简单的 Swing 应用程序,其中 JEditorPane 封装在 JScrollPane 中。
不幸的是,屏幕阅读器软件如 JAWS 或 NVDA 行为不正确。
当焦点进入 JEditorPane 时,它仅读取可访问名称,后跟“文本”,然后停止,而预期行为是继续读取 JEditorPane 的内容。
如果我不将 JEditorPane 包装在 JScrollPane 中,它会按预期工作。
我尝试使用 Monkey 检查可访问的树,但我看不到封装在 JScrollPane 中的 JEditorPane 与未封装的 JEditorPane 之间有任何相关差异。
有什么想法吗?
这是演示该问题的一个简短示例。如果焦点进入第一个 JEditorPane,JAWS 将读取“第一个编辑器窗格 - 编辑”。如果焦点进入第二个 JEditorPane,JAWS 会读取“第二个编辑器窗格 - 编辑 - 栏”。
public final class SmallExample {
public static void main(String... aArgs){
JFrame frame = new JFrame("Test Frame");
JPanel panel = new JPanel();
JEditorPane editorPane1 = new JEditorPane();
editorPane1.setText("Foo");
editorPane1.getAccessibleContext().setAccessibleName("first editorpane");
editorPane1.getAccessibleContext().setAccessibleDescription("");
JScrollPane scrollPane = new JScrollPane( editorPane1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
panel.add(scrollPane);
JEditorPane editorPane2 = new JEditorPane();
panel.add(editorPane2);
editorPane2.setText("Bar");
editorPane2.getAccessibleContext().setAccessibleName("second editorpane");
editorPane2.getAccessibleContext().setAccessibleDescription("");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
I have a simple Swing application with a JEditorPane wrapped in a JScrollPane.
Unfortunately screen reader software like JAWS or NVDA does not behave correctly.
When focus enters the JEditorPane it only reads the accessible name followed by "text" and then stops, when the expected behavior is to continue reading the contents of the JEditorPane.
If I do not wrap the JEditorPane in the JScrollPane it works as expected.
I have tried inspecting the accessible tree using Monkey, but I cannot see any relevant difference between a JEditorPane wrapped in a JScrollPane and one that is not wrapped.
Any ideas?
Here is a brief sample that demonstrates the problem. If focus enters the first JEditorPane, JAWS reads "first editorpane - edit". If focus enters the second JEditorPane, JAWS reads "second editorpane - edit - bar".
public final class SmallExample {
public static void main(String... aArgs){
JFrame frame = new JFrame("Test Frame");
JPanel panel = new JPanel();
JEditorPane editorPane1 = new JEditorPane();
editorPane1.setText("Foo");
editorPane1.getAccessibleContext().setAccessibleName("first editorpane");
editorPane1.getAccessibleContext().setAccessibleDescription("");
JScrollPane scrollPane = new JScrollPane( editorPane1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
panel.add(scrollPane);
JEditorPane editorPane2 = new JEditorPane();
panel.add(editorPane2);
editorPane2.setText("Bar");
editorPane2.getAccessibleContext().setAccessibleName("second editorpane");
editorPane2.getAccessibleContext().setAccessibleDescription("");
frame.getContentPane().add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到了一个解决方法:
如果我
那么它就可以工作。
我仍然非常感谢任何关于为什么这样做有效的见解(我找到了解决方法,将 editorPane2 的 AccessibleContext 替换为 editorPane1 的 AccessibleContext,并逐渐切换回方法,直到找到我需要的方法覆盖)。
这是一个工作示例(不再那么简短了):
I found a workaround myself:
If I
then it works.
I would still very much appreciate any insight into why this works (I found the workaround by replacing the AccessibleContext for editorPane2 with the one for editorPane1 and gradually switching the methods back until I found the ones that I needed to override).
Here is a working example (it is not so brief anymore):