@Override
    public void validate() {
        Graphics g = getGraphics();
        final FontMetrics fontMetrics = g.getFontMetrics();

        String[] allLines = content.split("\n");
        int allLinesN = allLines.length;
        int nLines = 0;

        int h = 0;
        for (int i = 0; i < allLinesN; ++i) {
            h += fontMetrics.getHeight();
            if (h <= textArea.getPreferredSize().height) {
                ++nLines;
            } else {
                break;
            }
        }


        String[] lineContents = new String[nLines];
        visibleContent = "";

        for (int i = 0; i < lineContents.length; ++i) {
            String l = "";
            String lin = allLines[i];
            int w = 0;
            for (char c : lin.toCharArray()) {
                w += fontMetrics.charWidth(c);
                if (w <= textArea.getPreferredSize().width) {
                    l += c;
                } else {
                    break;
                }
            }
            lineContents[i] = l;
            visibleContent += l + "\n";
        }

        updateLineContent(visibleContent, true);
        textArea.setText(visibleContent.trim());

    }