Java 中的代码字段

Code Field in Java

我正在尝试开发一个 java 应用程序来保存 我的代码片段 。我想从任何地方复制代码(比如 WhosebugnetbeansXcode)和将它们粘贴到我的应用程序中以保存它们的格式以便将来检索它们。 如何实现? jTextArea 是否支持格式化文本(带颜色的代码)?

谢谢。

来自 Oracle JTextArea 教程:

If you want the text area to display its text using multiple fonts or other styles, you should use an editor pane or text pane. If the displayed text has a limited length and is never edited by the user, use a label.

这意味着:不,您不能使用 JTextArea 来格式化您的代码,请使用 JEditorPane 或其子类 JTextPane (see this tutorial)