I can’t open the RTF document with JAVA. I reread some literature and found a JTextPane , JEditorPane , JFormatedTextField . The text only needs to be shown, so I selected JEditorPane .

 File InstructionFile = new File("Instruction.rtf"); tfInstruction = new JEditorPane("InstructionFile"); 

I tried to set the text using the file when initializing the JEditorPane , but for some reason this option does not work.

For JEditorPane in the environment, I found the property setDocument - and it seems that this is the method that I need, but I have no idea how to use it?

    1 answer 1

    To read RTF you can actually use Swing components. Examples here

    In general, in order not to be loaded with heavy Swing, you can simply use Apache POI

    There is a fairly well-developed API for working with office documents.

    • Thanks for the links, the method I need - read To show the RTF file in JEditorPane use the following code: JEditorPane editorPane = new JEditorPane (); editorPane.setEditorKit (new AdvancedRTFEditorKit ()); editorPane.read (new FileInputStream (pathToRTFFile)); but why this code does not work tfInstruction = new JEditorPane (); // JEditorPane.setEditorKit (new AdvancedRTFEditorKit ()); tfInstruction.read (new FileInputStream ("Instruction.rtf")); The error indicates the Read method, requires another Object parameter, tell me what you need to add - pj-infest