35

The rich text editor must be implemented in Java, provide Swing support, and preferably be open source.

I'm looking to integrate it into an existing Java/Swing application.

Thanks.

Ben Combee
  • 16,831
  • 6
  • 41
  • 42
fred smith
  • 359
  • 1
  • 3
  • 4
  • I have no idea abt Swing, but [jEdit](http://www.jedit.org/) seems to be fully Java.. And its open source too – nawfal Feb 26 '13 at 15:29

5 Answers5

23

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 display rtf or html, just set the encoding type before you fill it with content.

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.

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()).

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.

ice1000
  • 6,406
  • 4
  • 39
  • 85
dalyons
  • 1,304
  • 3
  • 15
  • 23
10

Try the MetaPhase editor, based on Charles Bell's HTMLDocumentEditor. It's LGPL v3 licensed and it's great, particularly as an example of using the StyledEditorKit, discussed here.

Community
  • 1
  • 1
user328744
  • 101
  • 1
  • 3
  • While it contains some bugs, it has enough features out of the box.. I'm looking now at how extensible the whole system is.. Maybe one can squeeze a couple of features more (like adding an image from the disk drive).. – pek Sep 07 '10 at 10:33
  • 3
    The URL above appears to be dead, try this: http://kenai.com/projects/metaphaseeditor. – Jon Iles Jul 05 '12 at 08:16
  • The URL is dead again--does anyone have a working link? – midrare Nov 06 '21 at 09:31
8

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.

Alexander Malfait
  • 2,691
  • 1
  • 23
  • 23
  • 3
    Probably overkill but it is definitively the ultimate solution :D – Mario Ortegón Oct 13 '08 at 23:36
  • 1
    It works fine. But is not an easy solution, as the OOBean is an Heavy weight component while Swing is Light weight. The combination of the both mechanism is not ideal. – lvr123 Dec 17 '15 at 11:23
7

I checked around and I can't find a jar file with just a text editor in it. However, heres 2 other options

Option A Use 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

Option B Scavenge 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).

  1. Memoranda (GPL): Its text edit or is in net.sf.memoranda.ui.htmleditor.HTMLEditor. Its a JPanel and only uses one other class.
  2. 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.

There are also a bunch of commercial ones available, assuming you have a budget :)

4

Have a look at JWord or 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.

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.

Might help.

Guner Sen
  • 41
  • 1