public class HTMLEditorReader extends JPanel{
// Composants permettant de visualiser un document
protected JTextPane viewer = new JTextPane();
protected JEditorPane sourcePane = new JEditorPane();
protected JPanel panel = new JPanel();
protected HTMLEditorKit k = new HTMLEditorKit();
protected HTMLDocument doc = (HTMLDocument)k.createDefaultDocument();
//protected EditorKit kit = new EditorKit();
public HTMLEditorReader(){
showTree();
this.setMinimumSize(new Dimension(800,600));
}
public void showTree(){
sourcePane.setEditable(false);
JScrollPane scrollPane = new JScrollPane(sourcePane);
sourcePane.setSize(new Dimension(800,600));
this.add(scrollPane);
sourcePane.setEditorKit(new HTMLEditorKit());
//onlit dans le fichier
FileReader reader = null;
try {
System.out.println("Loading");
reader = new FileReader("Test.html");
HTMLEditorKit htmlKit = new HTMLEditorKit();
HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
HTMLEditorKit.Parser parser = new ParserDelegator();
HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
parser.parse(reader, callback, true);
sourcePane.setDocument(htmlDoc);
System.out.println("Loaded");
}catch (IOException exception) {
System.out.println("Load oops");
exception.printStackTrace();
}
}
public static void main(String[]args){
JFrame fenetre = new JFrame("HTML EDITOR READER");
fenetre.getContentPane().add(new HTMLEditorReader());
//this.setLocation(300, 300);
fenetre.pack();
fenetre.setVisible(true);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
}