Java String Format formatTooltip(String tooltip)

Here you can find the source of formatTooltip(String tooltip)

Description

format Tooltip

License

Open Source License

Declaration

public static List<String> formatTooltip(String tooltip) 

Method Source Code

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

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> formatTooltip(String tooltip) {
        return formatTooltip(tooltip, 45);
    }//from ww  w  .j a va2 s. c o  m

    public static List<String> formatTooltip(String tooltip, int length) {
        List<String> formattedTooltip = new ArrayList<String>();

        while (!tooltip.isEmpty()) {
            if (tooltip.length() > length) {
                int lastSpaceIndex = 0;

                for (int i = 0; i < length; i++) {
                    if (tooltip.charAt(i) == ' ')
                        lastSpaceIndex = i;
                }
                formattedTooltip.add(tooltip.substring(0, lastSpaceIndex));
                tooltip = tooltip.substring(lastSpaceIndex);
            } else {
                formattedTooltip.add(tooltip);
                tooltip = "";
            }
        }

        return formattedTooltip;
    }
}

Related

  1. formatNameToMimeType(final String formatName)
  2. formatParam(String param)
  3. formatProtein(String seq)
  4. formatString(String stringFormat, String... args)
  5. formatStringTo80Columns(String str)
  6. formatTreeLines(String tree)
  7. formatVarname(StringBuilder buffer, Object varname)
  8. formatWords(String words, String delimiter, boolean isHeaderUpperCase)
  9. getAnswerKey(String itemFormat)