I've been lead to believe that HTML formatting can be used on SWING components by setting the text property to an HTML string similar to the following: "<html>bold text". I have not been able to get this to work. Does anyone have any ideas? Thanks VG
Changing Styles Then, at the appropriate time, you can use either the various methods shown in the following table of StyleConstants to change the style of the selected contents within the JTextPane or StyledDocument methods such as setCharacterAttributes(), setParagraphAttributes(), or just plain setLogicalStyle() to change the document characteristics. Just create a SimpleAttributeSet, and configure any attribute you would like.
void setAlignment() void setBackground() void setBidiLevel() void setBold() void setComponent() void setFirstLineIndent() void setFontFamily() void setFontSize() void setForeground() void setIcon() void setItalic() void setLeftIndent() void setLineSpacing() void setRightIndent() void setSpaceAbove() void setSpaceBelow() void setSubscript() void setSuperscript() void setTabSet() void setUnderline() StyleConstants methods for changing attributes of currently selected content. You will also need to setCharacterAttributes() or setParagraphAttributes() the JTextPane. void replaceSelection() void insertComponent() void insertIcon() JTextPane methods to replace currently selected content with a String, Component, or Icon void setLogicalStyle() JTextPane method to changes Style of current paragraph In some cases, you may want to wrap one of the style changing methods into an ActionListener and make it available on a menu or a button. To make things easier, most of these adapters have already been created for you. With either of these methods, you won't have to worry about finding the selected text to figure out what to change. A third method of changing styles allows you to not worry about specific class names, just functionality. The StyledEditorKit class provides a minimal set of text actions as a series of inner classes as shown in the table.
StyledEditorKit.AlignmentAction AlignmentAction (String textAction, int alignment) StyledEditorKit.BoldAction BoldAction() StyledEditorKit.FontFamilyAction FontFamilyAction (String textAction, String family) StyledEditorKit.FontSizeAction FontSizeAction (String textAction, int size) StyledEditorKit.ForegroundAction ForegroundAction (String textAction, Color color) StyledEditorKit.ItalicAction ItalicAction() StyledEditorKit.StyledTextAction abstract parent of others StyledEditorKit.UnderlineAction UnderlineAction()