How to change the Element structure of a DefaultSyledDocument

Hello,
I'm trying to override the insertUpdate method of DefaultStyledDocument so that I could build my own Element structure by adding my own BranchElement- and LeafElement-s. If I examine the Element hierarchy everything seems OK. But when I use my document in a JTextPane. I get the error Exception in thread "AWT-EventQueue-0" javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Invalid location (I add the whole dump at the end of this message), whenever I add a new line to the document (to test this compile and run the included code and press then newline after the 'He' in 'Hello'. I suspect that the error is caused by the fact that the view hierarchy is not updated correctly but I'm not sure. To be honest I have searched for a while for some example code, explaning how you can make your own element hierarchy in a DefaultStyledDocument (without using ElementBuffer), but to no avail.
Can any of the Text gurus here shed some lights on my code and see what is wrong with it or point me to some example code.
Thanks a lot in advance.
Marc Mertens
Full Stack Dump
Exception in thread "AWT-EventQueue-0" javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Invalid location
at javax.swing.text.GlyphView.getText(GlyphView.java:117)
at javax.swing.text.GlyphPainter1.getSpan(GlyphPainter1.java:43)
at javax.swing.text.GlyphView.getPreferredSpan(GlyphView.java:537)
at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:689)
at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:216)
at javax.swing.text.BoxView.checkRequests(BoxView.java:911)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:879)
at javax.swing.text.BoxView.checkRequests(BoxView.java:911)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:325)
at javax.swing.text.BoxView.layout(BoxView.java:682)
at javax.swing.text.BoxView.setSize(BoxView.java:379)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1618)
at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:812)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1615)
at javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1227)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:769)
at java.awt.Container.layout(Container.java:1401)
at java.awt.Container.doLayout(Container.java:1390)
at java.awt.Container.validateTree(Container.java:1473)
at java.awt.Container.validate(Container.java:1448)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:379)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:113)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-0" javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Invalid location
at javax.swing.text.GlyphView.getText(GlyphView.java:117)
at javax.swing.text.GlyphPainter1.getSpan(GlyphPainter1.java:43)
at javax.swing.text.GlyphView.getPreferredSpan(GlyphView.java:537)
at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:689)
at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:216)
at javax.swing.text.BoxView.checkRequests(BoxView.java:911)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:879)
at javax.swing.text.BoxView.checkRequests(BoxView.java:911)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:325)
at javax.swing.text.BoxView.layout(BoxView.java:682)
at javax.swing.text.BoxView.setSize(BoxView.java:379)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1618)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:946)
at javax.swing.text.DefaultCaret.repaintNewCaret(DefaultCaret.java:1246)
at javax.swing.text.DefaultCaret$1.run(DefaultCaret.java:1225)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Exception in thread "AWT-EventQueue-0" javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Invalid location
at javax.swing.text.GlyphView.getText(GlyphView.java:117)
at javax.swing.text.GlyphPainter1.getSpan(GlyphPainter1.java:43)
at javax.swing.text.GlyphView.getPreferredSpan(GlyphView.java:537)
at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:689)
at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:216)
at javax.swing.text.BoxView.checkRequests(BoxView.java:911)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:879)
at javax.swing.text.BoxView.checkRequests(BoxView.java:911)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:325)
at javax.swing.text.BoxView.layout(BoxView.java:682)
at javax.swing.text.BoxView.setSize(BoxView.java:379)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1618)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:946)
at javax.swing.text.DefaultCaret.setVisible(DefaultCaret.java:952)
at javax.swing.text.DefaultCaret.focusLost(DefaultCaret.java:347)
at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:172)
at java.awt.Component.processFocusEvent(Component.java:5380)
at java.awt.Component.processEvent(Component.java:5244)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1810)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:840)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:530)
at java.awt.Component.dispatchEventImpl(Component.java:3841)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.SentEvent.dispatch(SentEvent.java:50)
at java.awt.DefaultKeyboardFocusManager$DefaultKeyboardFocusManagerSentEvent.dispatch(DefaultKeyboardFocusManager.java:161)
at java.awt.DefaultKeyboardFocusManager.sendMessage(DefaultKeyboardFocusManager.java:188)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:595)
at java.awt.Component.dispatchEventImpl(Component.java:3841)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Window.dispatchEventImpl(Window.java:1778)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.SequencedEvent.dispatch(SequencedEvent.java:93)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.ThreadDeath
at java.lang.Thread.stop(Thread.java:698)
at java.lang.ThreadGroup.stopOrSuspend(ThreadGroup.java:671)
at java.lang.ThreadGroup.stop(ThreadGroup.java:584)
at org.netbeans.core.execution.DefaultSysProcess.stop(DefaultSysProcess.java:54)
at org.netbeans.core.execution.ProcessNodeItem$1.stop(ProcessNodeItem.java:41)
at org.netbeans.core.execution.ProcessNodeItem$TerminateProcessAction.performAction(ProcessNodeItem.java:69)
at org.openide.util.actions.NodeAction$3.run(NodeAction.java:531)
at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:47)
at org.openide.util.actions.NodeAction$DelegateAction.actionPerformed(NodeAction.java:527)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1778)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
package Document;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.AbstractDocument.*;
* EditorDocument.java
* Created on September 10, 2006, 3:58 PM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
* Document to represent the content of a syntax highlighting editor
* @author marc
public class EditorDocument extends DefaultStyledDocument {
    /** List of the white space characters */
    private char[] _whiteSpaceChars;
    /** List of the delimiter characters */
    private char[] _delimiterChars;
    /** Creates a new instance of EditorDocument */
    public EditorDocument(char[] whiteSpaceChars,char[] delimiterChars) {
        _whiteSpaceChars=whiteSpaceChars;
        _delimiterChars=delimiterChars;
     * Updates document structure as a result of text insertion.  This
     * will happen within a write lock.  Since this document simply
     * maps out lines, we refresh the line map.
     * @param chng the change event describing the dit
     * @param attr the set of attributes for the inserted text
    protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr) {
        int begin=Math.max(0,chng.getOffset()-1);
        int end=begin+chng.getLength()+1;
        Element rootElement=getDefaultRootElement();
        int index;
        int m=rootElement.getElementCount();
        AbstractDocument.BranchElement line;
        super.insertUpdate(chng,attr);
        // Add the tokens
        index=rootElement.getElementIndex(begin);
        m=rootElement.getElementCount();
        if (index>=0)
            for (;index<m && (line=(AbstractDocument.BranchElement) rootElement.getElement(index)).getStartOffset()<=end;index++) {
            chng.addEdit(addTokens(line,attr));
        //fireChangedUpdate(chng);
    protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng,AttributeSet attr) {
        int begin=chng.getOffset();
        int end=begin+chng.getLength();
        BranchElement root=(BranchElement) getDefaultRootElement();
        // Find the lines that must be removed
        int indexFirstLine=root.getElementIndex(begin);
        int indexLastLine=root.getElementIndex(end);
        BranchElement[] removeLines=new BranchElement[indexLastLine-indexFirstLine+1];
        for (int i=indexFirstLine;i<=indexLastLine;i++)
            removeLines=(BranchElement) root.getElement(i);
// Add the lines must replace the removed lines
int beginFirstLine=removeLines[0].getStartOffset();
int endLastLine=removeLines[removeLines.length-1].getEndOffset();
Segment segment=new Segment();
ArrayList<BranchElement> newLines=new ArrayList<BranchElement>(removeLines.length); // Guess the length of the new lines
try {
getText(beginFirstLine,endLastLine,segment);
char c=segment.current();
BranchElement line;
while (c!=Segment.DONE) {
if (c=='\n') {
line=new BranchElement(root,attr);
newLines.add(line);
addTokens(line,attr,beginFirstLine,segment.getIndex()+1);
beginFirstLine=segment.getIndex()+1;
c=segment.next();
if (beginFirstLine<endLastLine) {
line=new BranchElement(root,attr);
newLines.add(line);
addTokens(line,attr,beginFirstLine,endLastLine);
// Add the lines to the Root element
BranchElement[] linesAdded=newLines.toArray(new BranchElement[newLines.size()]);
root.replace(indexFirstLine,indexLastLine-indexFirstLine+1,linesAdded);
// Notify listeners
DefaultDocumentEvent edit=new DefaultDocumentEvent(begin,end-begin,DefaultDocumentEvent.EventType.CHANGE);
edit.addEdit(new ElementEdit(root,indexFirstLine,removeLines,linesAdded));
fireChangedUpdate(edit);
} catch (Exception e) {
throw new EditorException("Error in insertUpdate, message was "+e.getMessage(),e);
//super.insertUpdate(chng,attr);
private void addTokens(AbstractDocument.BranchElement line,AttributeSet attr,int begin,int end) {
try {
ArrayList<TokenElement> childTokens=new ArrayList<TokenElement>();
int strLength=end-begin;
// Create the new tokens
Segment segment=new Segment();
getText(begin,end-begin,segment);
char c;
int b=0;
TokenElement token;
//System.out.println(str);
c=segment.current();
while (c!=Segment.DONE) {
if (isWhite(c)) {
// Whitespace character
if (b<segment.getIndex()) {
token=new TokenElement(line,attr,begin+b,begin+segment.getIndex(),false);
childTokens.add(token);
b=segment.getIndex();
// Find all the white spaces
while ((c=segment.next())!=Segment.DONE && isWhite(c));
token=new TokenElement(line,attr,begin+b,begin+segment.getIndex(),true);
childTokens.add(token);
b=segment.getIndex(); // Begin of next token
} else if (isDelimiter(c)) {
// Delimiter
if (b<segment.getIndex()) {
token=new TokenElement(line,attr,begin+b,begin+segment.getIndex(),false);
childTokens.add(token);
token=new TokenElement(line,attr,begin+segment.getIndex(),begin+segment.getIndex(),c);
childTokens.add(token);
b=segment.getIndex();
c=segment.next();
} else {
c=segment.next();
if (b<segment.getIndex()) {
token=new TokenElement(line,attr,begin+b,begin+segment.getIndex(),false);
childTokens.add(token);
Element[] removed=new Element[line.getElementCount()];
for (int i=0;i<removed.length;i++)
removed[i]=line.getElement(i);
TokenElement[] newElements=childTokens.toArray(new TokenElement[childTokens.size()]);
line.replace(0,line.getElementCount(),newElements);
} catch (Exception e) {
throw new EditorException("Unexpected BadlocationException ");
* Returns a iterator of the tokens starting from the given position
* @param The position that is covered by the first token returned by this iterator
* @return A iterator of all the tokens starting at the given position
public Iterator<IToken> getTokensFrom(int position) {
return new TokenIterator(position);
private String getText(Element element) {
int begin=element.getStartOffset();
int end=Math.min(element.getEndOffset(),getLength());
try {
return getText(begin,end-begin);
} catch (BadLocationException e) {
throw new EditorException("Unexpected BadLocationException (this should not happen at all)");
* Check if a character is a white space
* @return True if a character is a white space
private boolean isWhite(char c) {
if (c=='\n') // End of line is always a white space
return true;
for (char whiteChar : _whiteSpaceChars)
if (whiteChar==c)
return true;
return false;
* Check if a character is a delimiter character (different from a white space character)
* @return True if a character is a delimiter character
private boolean isDelimiter(char c) {
for (char delimiterChar : _delimiterChars)
if (delimiterChar==c)
return true;
return c=='\0';
* Test code
public static void main(String[] args) {
// Display a test frame containing a test document
try {
JFrame frm=new JFrame();
EditorDocument doc=new EditorDocument(new char[] {' ','\n','\t','\r'},new char[0]);
doc.insertString(0,"Hello",null);
JTextPane pane=new JTextPane(doc);
JScrollPane scroll=new JScrollPane(pane);
frm.getContentPane().add(scroll);
frm.setSize(200,300);
frm.setVisible(true);
} catch (Exception e) {
* Class that is a iterator over the tokens in the document
private class TokenIterator implements Iterator<IToken> {
private int _lineIndex=-1;
private int _tokenIndex=-1;
public TokenIterator(int position) {
AbstractDocument.BranchElement root=(AbstractDocument.BranchElement) getDefaultRootElement();
_lineIndex=root.getElementIndex(position);
AbstractDocument.BranchElement line=(AbstractDocument.BranchElement) root.getElement(_lineIndex);
_tokenIndex=line.getElementIndex(position)-1;
* Removes from the underlying collection the last element returned by the
* iterator (optional operation). This method can be called only once per
* call to <tt>next</tt>. The behavior of an iterator is unspecified if
* the underlying collection is modified while the iteration is in
* progress in any way other than by calling this method.
* @exception UnsupportedOperationException if the <tt>remove</tt>
*           operation is not supported by this Iterator.
* @exception IllegalStateException if the <tt>next</tt> method has not
*           yet been called, or the <tt>remove</tt> method has already
*           been called after the last call to the <tt>next</tt>
*           method.
public void remove() {
// Do nothing
* Returns the next element in the iteration. Calling this method
* repeatedly until the {@link #hasNext()} method returns false will
* return each element in the underlying collection exactly once.
* @return the next element in the iteration.
* @exception NoSuchElementException iteration has no more elements.
public IToken next() {
Element root=getDefaultRootElement();
if (_lineIndex>=root.getElementCount())
return null;
Element line=root.getElement(_lineIndex);
_tokenIndex++;
if (_tokenIndex>=line.getElementCount()) {
_lineIndex++;
if (_lineIndex>=root.getElementCount())
return null;
line=root.getElement(_lineIndex);
if (line.getElementCount()==0)
return null;
_tokenIndex=0;
return (IToken) line.getElement(_tokenIndex);
* Returns <tt>true</tt> if the iteration has more elements. (In other
* words, returns <tt>true</tt> if <tt>next</tt> would return an element
* rather than throwing an exception.)
* @return <tt>true</tt> if the iterator has more elements.
public boolean hasNext() {
int lineIndex=_lineIndex;
int tokenIndex=_tokenIndex;
Element root=getDefaultRootElement();
if (lineIndex>=root.getElementCount())
return false;
Element line=root.getElement(lineIndex);
tokenIndex++;
if (tokenIndex>=line.getElementCount()) {
lineIndex++;
if (lineIndex>=root.getElementCount())
return false;
line=root.getElement(lineIndex);
if (line.getElementCount()==0)
return false;
return true;
* Represents a token in the document
private class TokenElement extends AbstractDocument.LeafElement implements IToken, Comparable<TokenElement> {
private boolean _isWhiteSpace;
private char _separatorChar='\0';
public TokenElement(Element parent,AttributeSet attributeSet,int offs0,int offs1,boolean whiteSpace) {
super(parent,attributeSet,offs0,offs1);
_isWhiteSpace=whiteSpace;
public TokenElement(Element parent,AttributeSet attributeSet,int offs0,int offs1,char separatorChar) {
super(parent,attributeSet,offs0,offs1);
_separatorChar=separatorChar;
* Returns the separator character if this token is a separator, returns '\0' otherwise
* @return The separator charactor or null otherwise
public char getSeparatorChar() {
return _separatorChar;
* Compares this object with the specified object for order. Returns a
* negative integer, zero, or a positive integer as this object is less
* than, equal to, or greater than the specified object.<p>
* In the foregoing description, the notation
* <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
* <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
* <tt>0</tt>, or <tt>1</tt> according to whether the value of <i>expression</i>
* is negative, zero or positive.
* The implementor must ensure <tt>sgn(x.compareTo(y)) ==
* -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
* implies that <tt>x.compareTo(y)</tt> must throw an exception iff
* <tt>y.compareTo(x)</tt> throws an exception.)<p>
* The implementor must also ensure that the relation is transitive:
* <tt>(x.compareTo(y)>0 && y.compareTo(z)>0)</tt> implies
* <tt>x.compareTo(z)>0</tt>.<p>
* Finally, the implementer must ensure that <tt>x.compareTo(y)==0</tt>
* implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
* all <tt>z</tt>.<p>
* It is strongly recommended, but <i>not</i> strictly required that
* <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
* class that implements the <tt>Comparable</tt> interface and violates
* this condition should clearly indicate this fact. The recommended
* language is "Note: this class has a natural ordering that is
* inconsistent with equals."
* @param o the Object to be compared.
* @return a negative integer, zero, or a positive integer as this object
*           is less than, equal to, or greater than the specified object.
* @throws ClassCastException if the specified object's type prevents it
* from being compared to this Object.
public int compareTo(TokenElement o) {
return getStartOffset()-o.getStartOffset();
* Indicates this is a white space token
* @return true if this is a white space token false otherwise
public boolean isWhiteSpace() {
return _isWhiteSpace;
* Returns the string this token is representing
* @return The string behind this token
public String getText() {
return EditorDocument.this.getText(this);
class SearchToken implements IToken {
private int _offset;
public SearchToken(int offset) {
_offset=offset;
* @return The start of the token used in comparisation operations
public int getEndOffset() {
return _offset;
public int getStartOffset() {
return _offset;
public boolean isWhiteSpace() {
throw new EditorException("May not be called");
public String getText() {
throw new EditorException("May not be called");
public char getSeparatorChar() {
throw new EditorException("May not be called");

I am trying to add primitive syntax highlighting to my JTextPane and have serious problems which I already stated in this forum. Now I read from uncle_alice that the text package from swing is not ment for that and that I need to write my own JTextPane and my own document and view.
Can you explain what you mean by "writing my own JTextPane and View and Dcoument".
My own Document I already have in order to provide SQL-highlighting.
But what exactly do you mean by suggesting to write my own View! Whoever uses JTextPane doesnt really have much to do with its view. Can you give me a hint as I am completely stuck with an Exception : "javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Length must be positive"
can you pinpoint the standard text-package's deficiency? it lacks what? what is the best work around?
cheers
ioannis

Similar Messages

  • How to change the default structure when exporting data in CSV format?

    Hello,
    can some one tell us how to change the default structure in CRM when exporting lists in CSV format (with Option "Always use unformatted list format (CSV) for download" ? Because we want to add a new structure for our own -is it possible ?
    If it is possible where can we find these structure ? In the blueprint customizing ?
    Thank you very much,
    Christian

    There is a workaround to move from 1.5 version to the older 1.4 version. But this could be specific to the browser setting the JRE version.
    Excerpts from sun docs:
    However, a user can still run older versions. To do so, launch the Java Plug-in Control Panel for the older version, then (re)select the browser in the Browser tab.
    Example:
    Assume you are running on Microsoft Windows with Microsoft Internet Explorer, have first installed version 1.4.2, then version 5.0, and you want to run 1.4.2.
    Go to the j2re1.4.2\bin directory where JRE 1.4.2 was installed. On a Windows default installation, this would be here: C:\Program Files\Java\j2re1.4.2\bin
    Double-click the jpicpl32.exe file located there. It will launch the control panel for 1.4.2.
    Select the Browser tab. Microsoft Internet Explorer might still appear to be set (checked). However, when 5.0 was installed, the registration of the 1.4.2 JRE with Internet Explorer was overwritten by the 5.0 JRE.
    If Microsoft Internet Explorer is shown as checked, uncheck it and click Apply. You will see a confirmation dialog stating that browser settings have changed.
    Check Microsoft Internet Explorer and click Apply. You should see a confirmation dialog.
    Restart the browser. It should now use the 1.4.2 JRE for conventional APPLET tags.
    Details are here
    http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/jcp.html
    My system (Windows XP) has the version 1.5_09 set as the default. However i just installed JRE 1.5_06 and would like to revert back to _06 as the default JRE..
    Will update if i find more information

  • How to change the case structure to string input?

    Hi,
    I have the inner case structure that it will decide to set "DC Voltage" or "DC Current" mode. The "Output Function" contained the selection of function "DC Voltage" or "DC Current". So far it only work with DC Voltage not DC Current. My question is how do I change the case structure to string selector? When the output function is selected to DC Voltage then the case structure is selected DC voltage case. Please help Thanks.
    Attachments:
    test.vi ‏35 KB

    You don't really need to convert the value to a string? The problem is that the value of the individual ring items are not 0 and 1, as you assumed. The values generated by the controls are:
    DC Voltage: 1006
    DC Current: 1007.
    You can find this out by viewing the properties for the "Output Function" and going to the "Edit Items" tab.
    So, all you need to do is change the 0 to 1006 and the 1 to 1007 for your case items.
    By the way, your sequence frame serves no purpose.

  • How can  change the folder structure in Bex Analyser to match the Web

    Hi Experts,
    When I create a report using the Web Analyser and save it in My Portfolio or Bex Portfolio, I can't find the report (or folders) in Bex Analyser.
    How Can i change the folder structure in Bex Analyser to match the Web Analyser?

    Hi Reddy,
           As u have created reports and saved it in BEx portfolio or My portfolio it will be saved in the KM folder which is known as Knowledge management folder for the KM services such as feedback,rating etc.So u cant view them when u open in web analyzer.U can only see them when u save in favourites or the roles folders.
                              Hope this helps
                         Sunil Reddy

  • How to change the element of container in the task

    Hello,all.
      I am new for workflow,today i find a new problem:when i finish a activity in the template,the element of container in the task can not be changed. Why? And how to change?
      Thanx,

    Hi Nemo,
    What I understood from your query is as follows -
    You have worked with Task activity in a workflow template. Now you want to change the element in Task Container, which you are not allowed to do so.
    If above is your query, kindly find following solution -
    1. You must have used some BOR object in your task activity.
    1. If you have used automatic binding between the method of BOR and workflow task then automatically the container elements are created. Now if you want to change these container elements then recommended is to change them first in method of BOR and again link the method. Let these elements generate automatically as part of binding.
    2. If you don't have any binding between your BOR method and Task container then, you don't have any elements created automatically. So you can directly create new elements inside task.
    Hope this helps you.
    PS If the answer solved your query, plz close the thread by marking it solved and rewarding each reply.
    Regards

  • How to change the elements number in Number To Boolean Array Function VI

    Hi, I'm working on using the DAQ digital output to control the digital input of a DAC, and I used the Number To Boolean Array Function. VI to convert the number to a Boolean array. The maximum number should be 4096, therefore it should consist of 12 elements.
    For the description of the VI, it says Boolean array returns an array of 8, 16, 32, or 64 elements, depending on the number of bits in the integer. Therefore, I change the number of the channels in task to 16, but it still doesn't work. Any suggesitions are greatly appreciated.
    Thanks!
    Possible reason(s):
    Write cannot be performed, because the number of channels in the data does not match the number of channels in the task.
    When writing, supply data for all channels in the task. Alternatively, modify the task to contain the same number of channels as the data written.
    Number of Channels in Task: 12
    Number of Channels in Data&colon; 32
    Task Name: _unnamedTask<1B>
    Solved!
    Go to Solution.
    Attachments:
    DAC test.vi ‏47 KB

    Once you have the boolean array, you can resize it using array tools. For example you can use "reshape array" with a lenght of 12 to trim the array to 12 booleans elements (you can also use array subset).
    LabVIEW Champion . Do more with less code and in less time .

  • Editing Chart legends: How to change the line structure within the legend?

    Hi,
    I have one problem: I have several charts in Numbers and since I need to print them in black/white, colors cannot be used to differentiate between the lines. So if I have a dotted line and a solid line, the legend only shows me solid lines as line symbols, so the line structure is not reflected within the legend. Can I change that?

    _This question was already asked and responded._
    Put a text box with the true kind of line above the one displayed automatically.
    Yvan KOENIG (VALLAURIS, France) samedi 1 mai 2010 16:52:44

  • How to change the inventory structure

    I am now running Oracle 11.0.3, 15 users, AP,AR,GL,INV,OE and PO
    on MS NT platform. The existing inventory item is using 10
    segments and 20 characters which is very difficult for data
    entry. Thus I would like to change it to 1 segment and 10
    characters. I want to keep all transactions (all data) in AR,AP
    & GL and I would give up (purge way) all data in OE, PO and INV
    after restructuring as it has different structure on item master.
    One way is to create a new instance/database, re-configure the
    AR, AP & GL setting and convert all data from AR,AP & GL, then
    configure the new item master structure and re-enter about 500
    items. This will take too much time (20-30 mandays).
    The other way is after the month-end closing, disable all 10
    segments, purge way all transactions in INV, OE & PO. Then
    create a new segment with 10 characters and re-compile it. I
    would prefer this method as it has minimum effort.
    My question is whether the 2nd method is feasible or not? Will
    there be any problem in using this method?

    You don't really need to convert the value to a string? The problem is that the value of the individual ring items are not 0 and 1, as you assumed. The values generated by the controls are:
    DC Voltage: 1006
    DC Current: 1007.
    You can find this out by viewing the properties for the "Output Function" and going to the "Edit Items" tab.
    So, all you need to do is change the 0 to 1006 and the 1 to 1007 for your case items.
    By the way, your sequence frame serves no purpose.

  • How to change the default element tag using dbms_xmlgen

    here is my code that generate output for purchase order data. I followed the syntax shown in xml db developer guide.
    I am getting the results but element tags are CAPS letters( As the coloumn names in the type defenitions are stored in CAPS in Oracle). but I need to show in small letters as per my requirement.
    can anyone help me how to change the default tag names for elements.
    ==================================HERE IS THE CODE==================
    DECLARE
    qryCtx DBMS_XMLGEN.ctxHandle;
    result CLOB;
    BEGIN
    qryCtx := DBMS_XMLGEN.newContext
    ('SELECT PODL_H_T
    ( CLOSEDDATETIME ,
    COMPANY ,
    CAST(MULTISET
    (SELECT LINENUMBER ,
    COMPANY ,
    PURCHASEORDERID ,
    ITEM ,
    QUANTITYUM ,
    TOTALQUANTITY
    FROM cpo_wms_podl_LINES
    WHERE PURCHASEORDERID = PH.PURCHASEORDERID) as PurchaseOrderDetailList
    FROM cpo_wms_podl_HEADERS PH ');
    -- now get the result
    DBMS_XMLGEN.setRowSetTag(qryCtx, 'Receipts' );
    DBMS_XMLGEN.setRowTag(qryCtx, 'PurchaseOrder' );
    result := DBMS_XMLGEN.getXML(qryCtx);
    INSERT INTO temp_clob_tab VALUES (result);
    DBMS_XMLGEN.closeContext(qryCtx);
    END;
    -- select * from temp_clob_tab
    ===========create type script=====================
    cpo_wms_podl_HEADERS
    CREATE or replace TYPE PurchaseOrderDetail AS OBJECT(
    LINENUMBER VARCHAR2(400 BYTE),
    COMPANY VARCHAR2(400 BYTE),
    PURCHASEORDERID VARCHAR2(400 BYTE),
    ITEM VARCHAR2(400 BYTE),
    QUANTITYUM VARCHAR2(400 BYTE),
    TOTALQUANTITY NUMBER
    create type PurchaseOrderDetailList as table of PurchaseOrderDetail
    create table temp_clob_tab(result CLOB)
    create type podl_HEADERS_list_t as table of podl_HEADERS_t
    CREATE or replace TYPE PODL_H_T AS OBJECT
    CLOSEDDATETIME DATE,
    COMPANY VARCHAR2(400 BYTE),
    CREATEDDATETIME DATE,
    PURCHASEORDERID VARCHAR2(400 BYTE),
    SHIP_TO VARCHAR2(400 BYTE),
    linelist PurchaseOrderDetailList
    )

    but I need to show in small letters as per my requirement.add alias column names in double quotes as in
    SQL> select dbms_xmlgen.getxmltype('select dname "DeptName", loc "Location" from dept') dept_xml from dual
    DEPT_XML                                                                       
    <ROWSET>                                                                       
      <ROW>                                                                        
        <DeptName>ACCOUNTING</DeptName>                                            
        <Location>NEW YORK</Location>                                              
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>RESEARCH</DeptName>                                              
        <Location>DALLAS</Location>                                                
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>SALES</DeptName>                                                 
        <Location>CHICAGO</Location>                                               
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>OPERATIONS</DeptName>                                            
        <Location>BOSTON</Location>                                                
      </ROW>                                                                       
      <ROW>                                                                        
        <DeptName>SALES</DeptName>                                                 
        <Location>MUNICH</Location>                                                
      </ROW>                                                                       
    </ROWSET>                                                                      
    1 row selected.

  • How to change the font size of text element in smartform

    Hi
    i want to know how to change the font size of text element in smartform
    regards
    Gincy

    Hi
    You can create Smartstyles, in which you can define paragraph formats for texts and character formats for character level changes.
    Paragraph format ---> alignment, font size etc
    character format for ---> superscript, subscript.
    After creating, in your smartform, there will be a option in the text element to enter a style.
    You give the created style and you can use the paragraph and character formats i that style.
    Hope this is clear..
    Regards
    Sekar

  • How to change the screen element to be ineditable in Dynpro POV

    Hi Experts,  any one has experience on how to change the screen element to be ineditable in Dynpro POV?

    Write this piece of code in the PROCESS ON VALUE-REQUEST..
    PROCESS ON VALUE-REQUEST.
    FIELD MARA-MATNR MODULE matnr_mod.
    MODULE matnr_mod input.
    LOOP at Screen.
    if screen-name=<field_name>.
      screen-input = 0.
      modify screen.
    endif.
    ENDLOOP.
    ENDMODULE.
    Thanks
    Venkat.O

  • How to change the Settings in the Graphic structure. T Code CN41

    Hi,
    How to change the Settings in the Graphic structure. T Code CN41
    Iam using the T Code cn41 to know the diff in Duruation, work, remaining duration in diff project version. I am getting the Graph/curve with standard settings and system is not allowing to change the scale (Y-X Axis) the way i required.
    Pls advise me.
    Thanks in Advance.
    Raju

    Hi,
    Thanks for the reply. But please clarify a bit. Please below is my requirement.
    As per the SAP Avilable screen in T Code CN41,it is showing the scale of 1 and 2 only.
    Assume if it 12 Days as actual work VS Actual duration of 265 Hours .It is showing 2 = actual work of 12 days and 1= Actual duruation of 12 Days.  I want to have the scale in such a way that, we should be able to see from 0-100-200-300 Hours and Days 5-10-15-20.
    Can u pls advis how can i get these and also give me ur mail id so that i can send u the screen shot also.
    Regards
    Raju

  • How to change the field lenght in stanard structure.

    hai Gurus,
    When I enhanced the standard structure for the 1st time I got warning but I could able to replicate and pull the data from r3 to bw. When I tried to enhance it again it is not allowing me saying i the need to enhance the standard data field length or need to add a custom field for this. Can you tell me how can change the field length for a standard structure?.
    Thanks, VP.

    hi,
    u can add a custom field of the required length to your structure and write the exit to populate it. If its a standard field I dont think you will be able to alter the length of the field.
    Regards.

  • How to change the Validility period of the cost element

    Hi All,
    how to change the validity period of the cost element. In tranc code Ka02 only the text is allowed to change but i want to change the validity period of the cost element.
    best Regards
    stephen

    Hi All,
    Thanks for your response...........
    My  concern is, i have a document posted to 43100 GL Expense acct, which is also defined as cost element, GL field status G004(cost accts). But when the original document is posted no is no assignment of any cost object.
    But i have to reverse the document and when i use FB08, the reversal is popping up with error " Assignment of CO object is neccesaary " Assign the cost center.
    Is there any way we can update the cost center for posted docuemnt? if so how? and can i make the cost element invalid for previous month so that it will not ask for cost object and change the field status of the GL from g004 to G001 only for reversal and set it back after posting is done.
    Appreciate ur feedback and suitab;le points are rewarded with points.
    best

  • How to restrict the user to change the project structure but not the documents?

    Hi,
    I have created one project assigning different users in Solution manger. I want to risitrict some of the users to change the project structure but simultaneously allwoing the project documents to be created, edited or deleted using solar01 under Project documentation tab. For that I have followed the steps provided in the follwoing link.
    http://wiki.scn.sap.com/wiki/display/SM/Howto+Restrict+Changes+to+Project+Nodes+to+Assigned+Team+Members
    I am able to restrict the users to change the project structure, but I am not able to allow access to the project documents. It gives me the message "You are not authorised to change the project". This fulfills my one of the requirements. But, Is there any way  to restrict the user to change the project structure but not the documents?. Any help will be apperitiated.
    Thanks,
    Rutvik Uapdhyay. 

    Hi Rutvik,
    Basically there are 2 different authorization role ...you should look for and customize as per requirement in Z* namespace.
    role  - SAP_SOLAR01_ALL
    this take care of objects in Solar01 like tab access etc
    role -SAP_SOL_KW_ALL
    this takes care of entire documentation within solman
    hope this helps
    Regards
    Prakhar

Maybe you are looking for

  • Why do I keep getting Error 2 Apple Application Support not found

    I KEEP GETTING ERROR 2 PLEASE UNINSTALL AND REINSTALL IN WHICH I DID BUT GET THE SAME MESSAGE. I'M USING WINDOWS 7

  • Mavericks AirPlay Extend Desktop as FCPX A/V Output?

    Hi all, Has anybody been successful at using the new "Extend Desktop" mode for AirPlay in Mac OS X Mavericks to setup an AppleTV as an external monitor for Final Cut Pro X? I tried but when I go to Preferences...->Playback A/V Output says "None Found

  • How to code with respect to Serialization

    When I try to deSerialize a class I get NullPointerException. When another class tries to call public ShapeMultiPath getShapeMultiPath() it returns null. The method exists in a class that looks like package data; import java.io.Serializable; import c

  • Tns entry on client machine for a physical standby!

    Hi all. i am working on 10gR2 on RHEL4.I have created a physical standby on the same host. The primary and the standby database has different sid as prod and prodsb can i have one tns entry on the client machine so that they can connect to the databa

  • PC-Mac camera compatibility

    My boyfriend has a PC and I just got a new iBook G4...he has a webcam that works with MSN but won't work with my MSN because it is text only. What is a program that I could use to view his webcam? And then which webcam could I get later so that he wo