I am developing an application that uses JEditorPane to display data from a database.
The EditorPane is suppose to append resultSet
in HTML format.
My Problem is that the JEditorPane wipes away the first resultSet
and only displays the last resultSet
.
Below is excerpt of my code:
while(rs.next()){
String htmlComent = "<"html>"<b>
+ "<"head><"title><"/title>"</>
+ "<"body>"<b>
+ "<"hr>"
+ "<"b align='left'> Subject"+" : "+rs.getString(1)+"<"/b><"br>"
+ "<"b align='left'> Institution"+": "+rs.getString(2)+"<"/b><"br>"
+ "<"b align='left'> Date" +" "+": "+rs.getString(3)+"</b><br>"
+ "<"b align='left'> Minuted To "+": "+rs.getString(4)+"</b><"br>"
+ "<"b align='left'> Minuted by "+": "+rs.getString(5)+"<"/b><"br>"
+ "<"hr>"
+ "<"p align = 'left' ><"B>Comment<"/B><"/p>"
+ rs.getString(6)
+ "<"/body>"
+ "<"/head>"
+ "<"/html>";
append(htmlComent+ "\n" );
..............................
/**
* This method appends text to a JEditorPane
*/
public void append(String s) {
try {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc2 = new HTMLDocument();
editorPane.setEditorKit(kit);
editorPane.setDocument(doc2);
HTMLDocument doc = (HTMLDocument)editorPane.getDocument();
kit.insertHTML(doc, doc2.getLength(), s, 0, 0, null);
//kit.insertHTML(doc, doc2.getLength(),, s, 0, 0, null);
} catch(BadLocationException |IOException exc) {
JOptionPane.showMessageDialog(this, exc.getMessage());
}
}
..........................
Could anybody tell me where I am going wrong?