Java Graphics Draw String drawFormattedString(Graphics2D g2, String htmlStr, int x, int y, int w, int h)

Here you can find the source of drawFormattedString(Graphics2D g2, String htmlStr, int x, int y, int w, int h)

Description

draw Formatted String

License

Open Source License

Declaration

public static void drawFormattedString(Graphics2D g2, String htmlStr, int x, int y, int w, int h) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * MIT License// www . j a v  a  2 s .c  om
 *
 * Copyright (c) 2016 Ashur Rafiev
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *******************************************************************************/

import java.awt.Graphics2D;

import javax.swing.JLabel;

public class Main {
    public static final int TOP = 0;
    private static final JLabel htmlAssist = new JLabel();

    public static void drawFormattedString(Graphics2D g2, String htmlStr, int x, int y, int w, int h) {
        g2.translate(x, y);
        htmlAssist.setFont(g2.getFont());
        htmlAssist.setForeground(g2.getColor());
        htmlAssist.setVerticalAlignment(JLabel.TOP);
        htmlAssist.setBounds(0, 0, w, h);
        htmlAssist.invalidate();
        htmlAssist.setText(htmlStr);
        htmlAssist.paint(g2);
        g2.translate(-x, -y);
    }
}

Related

  1. drawCenteredText(Graphics2D g, String text, int x, int y, float align_x, float align_y, float font_size)
  2. drawCenteredText(java.awt.Graphics g, String s, java.awt.Rectangle rect)
  3. drawClippedString(Graphics g, String t, int x, int y, int width)
  4. drawEmphasizedString(Graphics g, Color foreground, Color emphasis, String s, int underlinedIndex, int x, int y)
  5. drawFitText(Graphics2D g2, int x, int y, int width, int height, String text)
  6. drawGradient(Graphics g, JComponent c, String prefix)
  7. drawGradientText(Graphics g, String text, int x, int y, Color c)
  8. drawLine(String pLine, Graphics2D pG, int pX, int pY, int pWidth, String pJustification)
  9. drawLineDrawChar(Graphics g, int x, int y, int bi, char c, int charWidth, int charHeight)