Java:语法突出显示组件键事件

发布于 2024-08-05 10:31:35 字数 605 浏览 3 评论 0原文

我刚刚遇到了 lib BeanShell。现在我正在制作一个带有运行按钮的 Java 编辑器,该编辑器无需编译即可运行代码。对于文本编辑器组件,我使用开源 jEdit 语法包。以下是演示链接:链接

现在我编写了代码,每次用户按下 Enter 键时都会自动添加与上一行开头相同数量的选项卡。我在一个简单的 JTextArea 中测试了该代码并且工作正常。但似乎键事件不适用于 JEditTextArea 我将此 JComponent 放在 JPanel 中。

JEditTextArea 是库中的编辑器组件。 (扩展JComponent

I just met the lib BeanShell. And now I'm making a Java Editor with a run-button who runs the code without compiling. For the texteditor-component, I use the open-source jEdit Syntax Package. Here is a link with a demo: link.

Now I wrote code that adds every time the user pressed enter automaticly added the same number of tabs like the previous line starts with. I tested that code in a simple JTextArea and works correctly. But it seems the keyevents are not working with the JEditTextArea
I put this JComponent in a JPanel.

The JEditTextArea is the editor-component in the lib. (Extends JComponent)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

数理化全能战士 2024-08-12 10:31:35

JEditTextArea 的行为与普通的 swing JTextComponent 不同。请参阅 JEditTextArea 中重写的 processKeyEvent 代码 - 它专门避免了 KeyListener 内容以提高性能。

我向 JEditTextArea 添加按键处理逻辑的方法是子类化 DefaultInputHandler 并覆盖 addDefaultKeyBindings,使用所需的绑定调用 addKeyBinding() 并逻辑。

The JEditTextArea doesn't behave like a normal swing JTextComponent. See the overridden processKeyEvent code in JEditTextArea - it specifically avoids the KeyListener stuff for performance.

The way I've added key handling logic to JEditTextArea is to subclass the DefaultInputHandler and override addDefaultKeyBindings, calling addKeyBinding() with your desired bindings and logic.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文