setForeground doesn't work on a Style(dDocument)
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
publicclass Documentextends JApplet
{
private JTextPane pane;
private JScrollPane scroller;
private StyledDocument document;
public Document()
{
pane =new JTextPane();
pane.setEnabled(false);
scroller =new JScrollPane(pane);
scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
add(scroller, BorderLayout.CENTER);
document = pane.getStyledDocument();
String text ="Hey what's up?";
Color color = Color.black;//Black right?
addText(text, color);
}
publicvoid addText(String text, Color color)
{
try
{
Style style = pane.addStyle("talk",null);
StyleConstants.setForeground(style, color);//DOESN'T WORK, but setBackground does work...weird...
StyleConstants.setFontFamily(style,"Verdana");
StyleConstants.setFontSize(style, 12);
StyleConstants.setBold(style,true);
StringTokenizer st =new StringTokenizer(text);
while(st.hasMoreTokens())
{
String word = st.nextToken();
document.insertString(document.getLength()," " + word, style);
}
document.insertString(document.getLength(),"\n", style);
}
catch(BadLocationException e)
{
e.printStackTrace();
}
}
}
Instead of using Style I also used MutableAttributeSet and SimpleAttributeSet...it all doesn't work.
Somebody knows why?

