Java HTML Encode toHTML(String msg)

Here you can find the source of toHTML(String msg)

Description

Turns the specified message into HTML code, for use with JLabels, tooltips and such, to achieve multiline text.

License

Open Source License

Declaration

public static String toHTML(String msg) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w  w w  . java2 s  .  c o  m*/
     * <p>
     * Turns the specified message into HTML code, for use with JLabels, tooltips and such,
     * to achieve multiline text.
     * </p>
     * 
     * <pre>
     * {@literal
     * Replaces '\n' with '<br/>', '>' and '<' with their HTML equivalents, and wraps
     * the message in <html></html> tags.
     * }
     * </pre>
     */
    public static String toHTML(String msg) {
        msg = msg.replaceAll("<", "&lt;");
        msg = msg.replaceAll(">", "&gt;");
        msg = msg.replaceAll("\n", "<br/>");
        return "<html>" + msg + "</html>";
    }
}

Related

  1. textToHtml(String text)
  2. textToHtml(String text)
  3. textToHTML(String text)
  4. textToHTML(String text)
  5. toHtml(String message)
  6. toHTML(String org, boolean inputValue)
  7. toHtml(String p_str)
  8. toHTML(String plainText)
  9. toHTML(String rawText)