Batch Text Inserts with JTextPane

Part II of “Faster JTextPane Text Insertion” describes another technique for overcoming some of JTextPane‘s performance limitations when initiatializing large documents with complex styles. The ElementSpec class, defined as part of DefaultStyledDocument, provides a way to batch updates and apply them in bulk. Depending on size and complexity of the document, the speed boost can …

Setting JTextPane Font and Color

Swing’s JTextPane supports styled text, embedded images and components, and other features not available in the AWT TextArea. However, basic operations like setting the font and color for the text are somewhat more complicated with JTextPane than with TextArea and other simpler text components. “Setting JTextPane Font and Color” illustrates the use of character attributes …

Vanishing Text Selections

In Java 1.3, opening a menu will temporarily hide selections in Swing text components. The glitch is mostly harmless, but can be disconcerting for users who are, for examples, selecting clipboard operations from a menu. “Fixing Disappearing Text Selections when a Menu is Opened” describes a simple fix for the problem.