匿名用户
1级
2006-03-19 回答
1. If your chat room is implemented using jsp, trying following:
2. If your chat room is implemented using Applet, then you can try following codes in your Applet class:
JTextPane jtp = new JTextPane();
add(jtp);
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = jtp.getStyledDocument().addStyle("regular", def);
StyleConstants.setFontFamily(def, "SansSerif");
Style s = jtp.getStyledDocument().addStyle("italic", regular);
StyleConstants.setItalic(s, true);
s = jtp.getStyledDocument().addStyle("small", regular);
StyleConstants.setFontSize(s, 10);
if ( id.equals( "who1" ) )
jtp.getStyledDocument().insertString(jtp.getStyledDocument().getLength(), "message1", jtp.getStyledDocument().getStyle("small"));
if ( id.equals( "who2" ) )
jtp.getStyledDocument().insertString(jtp.getStyledDocument().getLength(), "message2", jtp.getStyledDocument().getStyle("italic"));
参考资料:refer to jdk 1.4 api document