Code: Show/Hide public static JTextPane chatText = null; ... chatText = new JTextPane(); ... public static void append(Color c, String s) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); int len = chatText.getDocument().getLength(); // same value as getText().length(); chatText.setCaretPosition(len); // place caret at the end (with no selection) chatText.setCharacterAttributes(aset, false); chatText.setEditable(true); // Won't print text unless it's enabled chatText.replaceSelection(s); // Adds the new line (with Color) chatText.setEditable(false); // Disable so you can't backspace chat. } |
Code: Show/Hide JTextArea inputarea;
... myeventhandler = new EventHandler(); inputarea.getDocument().addDocumentListener(myeventhandler); ... class EventHandler implements DocumentListener { public void insertUpdate(DocumentEvent evt) { ... |
BDwinsAlt wrote: |
I had to modify it outside of the document listener. |
Smong wrote: |
What about writing a module that can send the news.txt to the chat client somehow. Or even better, a link to a website that gets loaded in part of the window, that way you can have more control over the layout of the news.txt. |
Animate Dreams wrote: |
Too many people uses .rtfs for their news.txt. |