谁能推荐一个Java富文本编辑器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/196980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can anyone recommend a Java rich text editor?
提问by fred smith
The rich text editor must be implemented in Java, provide Swing support, and preferably be open source.
富文本编辑器必须用 Java 实现,提供 Swing 支持,最好是开源的。
I'm looking to integrate it into an existing Java/Swing application.
我希望将其集成到现有的 Java/Swing 应用程序中。
Thanks.
谢谢。
回答by dalyons
This is probably not as drop-in-place as what you were after... but JTextPane supports rich text and HTML. Its trivial to get it to displayrtf or html, just set the encoding type before you fill it with content.
这可能不像您所追求的那样就地放置……但 JTextPane 支持富文本和 HTML。让它显示rtf 或 html 很简单,只需在填充内容之前设置编码类型。
As for making the little "B" and "I" etc style-modifying buttons, well if it came down to it, in a pinch that wouldnt be very hard to make yourself.
Think JButtons with Icons set. Their listeners get JTextPane's current selection start and end index positions like this :
jpane.getSelectionStart()
or jpane.getSelectionEnd()
and then insert opening and closing html/rtf tags at those locations.
至于制作小“B”和“ I”等风格修改按钮,好吧,如果归结为它,在紧要关头,自己制作起来并不难。想想带有图标的 JButtons。他们的侦听器像这样获取 JTextPane 的当前选择开始和结束索引位置:
jpane.getSelectionStart()
或者 jpane.getSelectionEnd()
然后在这些位置插入开始和结束 html/rtf 标签。
Undo is easy too - maintain a simple stack of the string contents of the Jpanel, every time the user does an edit action, a simple history.push(jpane.getText())
would store the state, and the undo button would be as simple as jpane.setText(history.pop())
.
撤消也很容易——维护一个简单的 Jpanel 字符串内容堆栈,每次用户进行编辑操作时,一个简单的history.push(jpane.getText())
将存储状态,撤消按钮将与jpane.setText(history.pop())
.
I/you could make one with B, I& undo in around 30 min I reckon - other buttons like lists will take longer, but not much so.
我/你可以用 B 做一个,我想在大约 30 分钟内撤消 - 其他按钮(如列表)会花费更长的时间,但不会太多。
回答by Alexander Malfait
You can embed the mother of all open source rich text editors in a Swing app: OpenOffice.org provides an "OOBean", using which you can embed a full OpenOffice instance in a Swing app.
您可以在 Swing 应用程序中嵌入所有开源富文本编辑器的母体:OpenOffice.org 提供了一个“OOBean”,您可以使用它在 Swing 应用程序中嵌入完整的 OpenOffice 实例。
回答by Alexander Malfait
I checked around and I can't find a jar file with just a text editor in it. However, heres 2 other options
我检查了一下,我找不到一个只有文本编辑器的 jar 文件。但是,这里有 2 个其他选项
Option AUse Swing and build one yourself. Swing has a lot of the componenets already covered in javax.swing.text, although it still requires an extensive amount of code. I found an example here
选项 A使用 Swing 并自己构建一个。Swing 有很多在 javax.swing.text 中已经涵盖的组件,尽管它仍然需要大量的代码。我在这里找到了一个例子
Option BScavenge code from an open source project. I found 2 projects with realy nice HTML WYSIWYG type editors that can be extracted (both are contained in just a few classes).
选项 B从开源项目中清除代码。我发现 2 个项目具有非常好的 HTML WYSIWYG 类型编辑器,可以提取(都包含在几个类中)。
- Memoranda(GPL): Its text edit or is in net.sf.memoranda.ui.htmleditor.HTMLEditor. Its a JPanel and only uses one other class.
- Ekit(LGPL): Its a full featured WYSIWYG Html editor. Its com.hexidec.ekit.EkitCore class is a JPanel and seems fairly multipurpose, although it uses a lot of other classes from the package.
- 备忘录(GPL):它的文本编辑或在 net.sf.memoranda.ui.htmleditor.HTMLEditor 中。它是一个 JPanel 并且只使用一个其他类。
- Ekit(LGPL):它是一个功能齐全的 WYSIWYG Html 编辑器。它的 com.hexidec.ekit.EkitCore 类是一个 JPanel 并且看起来相当多用途,尽管它使用了包中的许多其他类。
There are also a bunch of commercial ones available, assuming you have a budget :)
假设您有预算,还有一堆商业可用的:)
回答by Guner Sen
Have a look at JWordor JRichTextEditor
JWord is a commercial swing rich text editor, with tables, paging and RTF/opendoc/XML support. Also supports header/footer, multi-column layout, export HTML, SVG, WMF etc.
JWord 是一个商业 Swing 富文本编辑器,具有表格、分页和 RTF/opendoc/XML 支持。还支持页眉/页脚、多列布局、导出 HTML、SVG、WMF 等。
JRichTextEditor is an open source swing widget, that's quite ok for note taking. Supports images, a simple XML format for storage, export to PDF, HTML. Not as advanced as JWord, but open source.
JRichTextEditor 是一个开源的swing 小部件,非常适合做笔记。支持图像,一种用于存储的简单 XML 格式,导出为 PDF、HTML。不如 JWord 先进,但开源。
Might help.
可能有帮助。
回答by user328744
Try the MetaPhase editor, based on Charles Bell's HTMLDocumentEditor
. It's LGPL v3licensed and it's great, particularly as an example of using the StyledEditorKit
, discussed here.
试试基于 Charles Bell 的MetaPhase 编辑器HTMLDocumentEditor
。它是LGPL v3许可的,非常棒,特别是作为使用StyledEditorKit
,此处讨论的示例。