<p>How can a text file be displayed in <br>a editable JTextPane?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ioana_martin
Posted On:   Friday, March 15, 2002 01:20 AM

How can a text file be displayed in a editable JTextPane? I have tried next code lines but it doesn't work (the text is not displayed and the JTextPane is not editable). JTextPane textPane; StyleContext context=new StyleContext(); StyledDocument document=new DefaultStyledDocument(context.getStyle(StyleContext.DEFAULT_STYLE)); StyledEditorKit kit=new StyledEditorKit(); JScrollPane EditorPane; try{ kit.read(new FileReader(filename), document, 0) } catch(Exception ex){//....} textPane=new JTextPane(document); textPane.setEditorKit(kit); textPane.setContentType("te   More>>

How can a text file be displayed in a editable JTextPane?
I have tried
next code lines but it doesn't work (the text
is not displayed and the JTextPane is not editable).

			

JTextPane textPane;

StyleContext context=new StyleContext();

StyledDocument document=new DefaultStyledDocument(context.getStyle(StyleContext.DEFAULT_STYLE));

StyledEditorKit kit=new StyledEditorKit();

JScrollPane EditorPane;


try{

kit.read(new FileReader(filename), document, 0)

}

catch(Exception ex){//....}

textPane=new JTextPane(document);

textPane.setEditorKit(kit);

textPane.setContentType("text/plain");

EditorPane=new JScrollPane(textPane);

textPane.setCaretPosition(textPane.getSelectionStart());

textPane.setEditable(true);


Tnx.

   <<Less
About | Sitemap | Contact