0

I have a txt file that contains data for a dictionary project, and the file is formatted as below:

@acute /ei, ə/
* noun
- a mark that means excellent, given to something of the highest quality, esp. school work:
= The teacher gave me an A for my essay.+ Cô giáo cho tôi điểm A cho bài luận. 
- the first letter of the English alphabet
* preposition
- in or for each or every; per:
= Take one tablet three times a day.+ Uống thuốc 3 lần một ngày 

Basically, a word starts with an @, its types start with *, its meanings start with - and examples start with =, Vietnamese translation of examples start with +

I want to display this content in a JTextPane in Java Swing, in the following format but do not know how to start.

Can someone give me advice on how to do it?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
thu.vix
  • 43
  • 6
  • 1
    Can you write that as HTML? A `JTextPane` (or `JEditorPane`) supports (simple) HTML formatting. – Andrew Thompson Oct 23 '21 at 06:41
  • Looks like you'll need to use a Markdown to HTML converter, this will require you to do some googling to find a suitable library – MadProgrammer Oct 23 '21 at 06:53
  • `JTextPane` also supports _Rich Text Format_ (RTF). For converting plain text to RTF, refer to [Java 8: how to convert plain UTF-8 text into RTF (with symbols > 127)?](https://stackoverflow.com/questions/63549122/java-8-how-to-convert-plain-utf-8-text-into-rtf-with-symbols-127) and for using RTF in `JTextPane` refer to [load RTF into JTextPane](https://stackoverflow.com/questions/29524208/load-rtf-into-jtextpane) – Abra Oct 23 '21 at 06:54
  • your text has to be placed into a styleddocument object wrapper first https://stackoverflow.com/questions/6068398/how-to-add-text-different-color-on-jtextpane nb you may need to call repaint() on your textpane component from time to time and call a useless abstract call to setColor method to cause the java.awt to load to another color in the code also. (long time since i've done that one). – Samuel Marchant Oct 23 '21 at 11:03

0 Answers0