For this case I would actually just set up JList (or something similiar) to take HTML code. Then you can use simple <
b> tags to bold things out, set colors with the <
font> tag.. bla bla bla
You have to remember that the parser is compatible up to HTML 3.2, hence having to use <
font> to set the color..
code snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Stack logData; JList log; JScrollPane logScroll; public Constructor() { logData = new Stack(); log = new JList(); log.setEnabled(false); logScroll = new JScrollPane(log); } public void log(String msg) { logData.push(msg); log.setListData(logData); Rectangle r = log.getBounds(); if (r.height >= logScroll.getBounds().height) { logScroll.getViewport().setViewPosition(new Point(0,r.height)); } } public void clear() { logData.clear(); log.setListData(logData); } |
Then you can just log HTML code..
1
| log("<html><font color=blue>This will be blue"); |
That way you don't have to worry about using those Style objects and such..
The above code is taken from a template GUI I use whenever I make a server-client app. The result looks decent: