private void highlightErrorLine(int lineIndex, JTextComponent component) {
        String text = component.getText() + "\n";
        int startPosition = 0;
        int endPosition = 0;

        for (int i = 0; i <= lineIndex; i++) {
            startPosition = endPosition > 0 ? endPosition + 1 : 0;
            endPosition = text.indexOf('\n', startPosition);
        }

        try {
            DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
            component.getHighlighter().addHighlight(startPosition, endPosition, highlightPainter);
        } catch (BadLocationException ex) {
            System.out.println("Unable to highlight line with index " + lineIndex + ": " + ex.getMessage());
        }
    }