JEditorPane editor = new JEditorPane(); // Instantiate a XMLEditorKit with wrapping enabled. XMLEditorKit kit = new XMLEditorKit( true); // Set the wrapping style. kit.setWrapStyleWord( true); editor.setEditorKit( kit); // Set the font style. editor.setFont( new Font( "Courier", Font.PLAIN, 12)); // Set the tab size editor.getDocument().putProperty( PlainDocument.tabSizeAttribute, new Integer(4)); // Enable auto indentation. editor.getDocument().putProperty( XMLDocument.AUTO_INDENTATION_ATTRIBUTE, new Boolean( true)); // Enable tag completion. editor.getDocument().putProperty( XMLDocument.TAG_COMPLETION_ATTRIBUTE, new Boolean( true)); // Set a style kit.setStyle( XMLStyleConstants.ATTRIBUTE_NAME, new Color( 255, 0, 0), Font.BOLD); // Put the editor in a panel that will force it to resize, when a different view is choosen. ScrollableEditorPanel editorPanel = new ScrollableEditorPanel( editor); JScrollPane scroller = new JScrollPane( editorPanel); ...
To switch between line wrapped and non wrapped views use:
... XMLEditorKit kit = (XMLEditorKit)editor.getEditorKit(); kit.setLineWrappingEnabled( false); // Update the UI and create a new view... editor.updateUI(); ...
@version $Revision: 1.4 $, $Date: 2005/03/28 15:20:26 $
@author Edwin Dankert
|
|