dcsimg

How do you initialize an AttributeSet variable so that it can be used in an insertString() method?

Sandip Chitale

Here's a simple example:


SimpleAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setUnderline(attrs, true);
StyleConstants.setForeground(attrs, unvisitedColor);
attrs.addAttribute(ID, new Integer(++linkID));
attrs.addAttribute(HTML.Attribute.HREF, url.toString());
doc.insertString(doc.getLength(), text, attrs);