@Override
        protected int drawSelectedText(final Graphics g, int x, int y,
                int p0, int p1)
                throws BadLocationException {
            // Same as drawUnselectedText, but without colors.
            final Font boldFont = g.getFont().deriveFont(Font.BOLD);
            final Font plainFont = g.getFont().deriveFont(Font.PLAIN);
            final Document doc = getDocument();
            
            boolean bold = false;
            boolean lastBold = false;
            
            int mark = p0;
            
            g.setColor(Color.BLACK);
            
            while (p0 < p1) {
                updateScanner(p0);
                int p = Math.min(scanner.getEndOffset(), p1);
                p = (p <= p0) ? p1 : p;
                
                MutableAttributeSet style = styles.getStyle(scanner.lastToken(), scanner.lastStr());
                bold = StyleConstants.isBold(style);
                
                if (bold != lastBold) {
                    // style change, flush what we have
                    g.setFont(lastBold ? boldFont : plainFont);
                    Segment text = getLineBuffer();
                    doc.getText(mark, p0 - mark, text);
                    x = Utilities.drawTabbedText(text, x, y, g, this, mark);
                    mark = p0;
                }
                lastBold = bold;
                p0 = p;
            }
            // flush remaining
            g.setFont(lastBold ? boldFont : plainFont);
            Segment text = getLineBuffer();
            doc.getText(mark, p1 - mark, text);
            return Utilities.drawTabbedText(text, x, y, g, this, mark);
        }