    private Image labelImage(BufferedImage image, String label) {
        if (label != null) {
            Graphics2D g2 = image.createGraphics();
            String[] words = label.split(" ");
            String longest = "";
            for (int i = 0; i < words.length; i++) {
                if (words[i].length() > longest.length()) {
                    longest = words[i];
                }
            }
            int rowGap = 3;
            int x;
            int y = rowGap;
            int iw = image.getWidth();
            int ih = image.getHeight();
            int fontSize = 10;
            Font font = new Font("SansSerif", Font.BOLD, fontSize);
            FontMetrics metrics = g2.getFontMetrics(font);
            while (!(metrics.getStringBounds(longest, g2).getWidth() < iw - 2) &&
                    fontSize > 5) {
                fontSize--;
                font = new Font("SansSerif", Font.BOLD, fontSize);
                metrics = g2.getFontMetrics(font);
            }
            g2.setFont(font);
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                           RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
            g2.setColor(Color.DARK_GRAY);
            Rectangle2D maxBounds = metrics.getMaxCharBounds(g2);
            int wh = (int) maxBounds.getHeight();
            for (int i = 0; i < words.length; i++) {
                Rectangle2D stringBounds = metrics.getStringBounds(words[i], g2);
                x = (int) (iw / 2 - stringBounds.getWidth() / 2);
                g2.drawString(words[i], x, y + wh);
                y += wh + rowGap;
            }
            g2.dispose();
        }
        return image;
    }

    private Image labelImage(BufferedImage image, String label) {
        if (label != null) {
            Graphics2D g2 = image.createGraphics();
            String[] words = label.split(" ");
            String longest = "";
            for (int i = 0; i < words.length; i++) {
                if (words[i].length() > longest.length()) {
                    longest = words[i];
                }
            }
            int rowGap = 3;
            int x;
            int y = rowGap;
            int iw = image.getWidth();
            int ih = image.getHeight();
            int fontSize = 10;
            Font font = new Font("SansSerif", Font.BOLD, fontSize);
            FontMetrics metrics = g2.getFontMetrics(font);
            while (!(metrics.getStringBounds(longest, g2).getWidth() < iw - 2) &&
                    fontSize > 5) {
                fontSize--;
                font = new Font("SansSerif", Font.BOLD, fontSize);
                metrics = g2.getFontMetrics(font);
            }
            g2.setFont(font);
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            g2.setColor(Color.DARK_GRAY);
            Rectangle2D maxBounds = metrics.getMaxCharBounds(g2);
            int wh = (int) maxBounds.getHeight();
            for (int i = 0; i < words.length; i++) {
                Rectangle2D stringBounds = metrics.getStringBounds(words[i], g2);
                x = (int) (iw / 2 - stringBounds.getWidth() / 2);
                g2.drawString(words[i], x, y + wh);
                y += wh + rowGap;
            }
            g2.dispose();
        }
        return image;
    }
