Dimension () { if (myPreferredSize == null) { int maxLineLength = 0; int linesCount = 0; for (LineTokenizer lt = new LineTokenizer(myRawText); !lt.atEnd(); lt.advance()) { maxLineLength = Math.max(maxLineLength, lt.getLength()); linesCount++; } FontMetrics fontMetrics = ((EditorImpl)getEditor()).getFontMetrics(myTextAttributes != null ? myTextAttributes.getFontType() : Font.PLAIN); int preferredHeight; int preferredWidth; if (myForceSingleLine) { preferredHeight = getEditor().getLineHeight(); preferredWidth = fontMetrics.charWidth('m') * myRawText.length(); } else { preferredHeight = getEditor().getLineHeight() * Math.max(1, linesCount); preferredWidth = fontMetrics.charWidth('m') * maxLineLength; } Insets insets = getInsets(); if (insets != null) { preferredHeight += insets.top + insets.bottom; preferredWidth += insets.left + insets.right; } myPreferredSize = new Dimension(preferredWidth, preferredHeight); } return myPreferredSize; }