TextLayout tl = new TextLayout(line, font, frc); maxWidth = Math.max(maxWidth, tl.getBounds().getWidth()); maxHeight = Math.max(maxHeight, tl.getBounds().getHeight());
if (!line.equals("")) { TextLayout tl = new TextLayout(line, font, frc); maxWidth = Math.max(maxWidth, tl.getBounds().getWidth()); maxHeight = Math.max(maxHeight, tl.getBounds().getHeight()); }
        public void setText(String str) {            BufferedImage bufferedImage = new BufferedImage(2, 2, BufferedImage.TYPE_4BYTE_ABGR_PRE);            Graphics2D g2d = (Graphics2D) (bufferedImage.createGraphics());            FontRenderContext frc = g2d.getFontRenderContext();            Font font = getFont();                        BufferedReader br = new BufferedReader(new StringReader(str));            String line;            double maxWidth = 0, maxHeight = 0;            int lines = 0;            try {                while ((line = br.readLine()) != null) {                    TextLayout tl = new TextLayout(line, font, frc);                    maxWidth = Math.max(maxWidth, tl.getBounds().getWidth());                    maxHeight = Math.max(maxHeight, tl.getBounds().getHeight());                    lines++;                }            } catch (IOException ex) {                ex.printStackTrace();            }            lines = (lines < 1) ? 1: lines;            int height = (int)(maxHeight * lines);            int width = (int)(maxWidth + 9); // ?            setPreferredSize(new Dimension(width, height));            super.setText(str);        }