Skip to content

Instantly share code, notes, and snippets.

@odinsbane
Created May 11, 2017 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odinsbane/715889310552aece017c4484c3733e43 to your computer and use it in GitHub Desktop.
Save odinsbane/715889310552aece017c4484c3733e43 to your computer and use it in GitHub Desktop.
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import java.util.ArrayList;
import java.util.List;
/**
* Created on 11.05.17.
*/
public class OthmEditor {
List<String> lines = new ArrayList<>();
final JEditorPane pane;
public OthmEditor(JEditorPane pane){
this.pane = pane;
}
public static void main(String[] args){
JFrame frame = new JFrame("appending");
JEditorPane pane = new JEditorPane();
pane.setText("<html><body>empty</body></html>");
pane.setContentType("text/html");
frame.add(pane);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new OthmEditor(pane).start();
}
public void start(){
for(int i = 0; i<100; i++){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(i%2==0){
lines.add("<div style='background-color:#ffff44'>counter: " + i + "</div>");
} else{
lines.add("<div style='background-color:#44ff44'>counter: " + i + "</div>");
}
pane.setText(getHtml());
}
}
public String getHtml(){
StringBuilder builder = new StringBuilder("<html><body>");
for(String line: lines){
builder.append(line);
}
builder.append("</body></html>");
return builder.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment