java - How to customize JLabel abbreviate text -
when text in label long jlabel abbreviate , add ... end. how can customized text ?
i have method abbreviate long text , dont know how can pass jlabel:
public static string abbreviatemiddle(string str, string middle, int length, int lengthsuffix) { if (stringutils.isempty(str) || stringutils.isempty(middle)) { return str; } if (length >= str.length() || length < (middle.length() + 2) || lengthsuffix > length || str.length() < lengthsuffix || length - middle.length() < lengthsuffix) { return str; } int targetsting = length - middle.length(); int endoffset = str.length() - lengthsuffix; int startoffset = targetsting - lengthsuffix; strbuilder builder = new strbuilder(length); builder.append(str.substring(0, startoffset)); builder.append(middle); builder.append(str.substring(endoffset)); return builder.tostring(); }
as shown here, label's ui delegate adds ellipsis required in layoutcl()
. resize frame se effect. can intercept result return whatever string
prefer.