split String For Tool Tip - Java Swing

Java examples for Swing:JTooltip

Description

split String For Tool Tip

Demo Code


//package com.java2s;

public class Main {
    public static String splitStringForToolTip(String string) {
        int DEFAULT_LINE_LENGHT = 100;
        StringBuffer buffer = new StringBuffer();
        buffer.append("<html>");
        int offset = 0;
        for (offset = 0; (offset + DEFAULT_LINE_LENGHT) < string.length(); offset = offset
                + DEFAULT_LINE_LENGHT) {
            buffer.append(string.substring(offset, offset
                    + DEFAULT_LINE_LENGHT));
            buffer.append("<p>");
        }/*  w ww.j  a  va  2s.  c  o  m*/
        buffer.append(string.substring(offset, string.length()));
        buffer.append("</html>");
        return buffer.toString();
    }
}

Related Tutorials