Created
May 11, 2017 09:11
-
-
Save odinsbane/715889310552aece017c4484c3733e43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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