开发者

Small problem in Java Swing

I have defined class ToolTipUI which extended BasicToolTipUI for propose of painting TipText of swing component, I used delimiter "|"(vertical bar) to differentiate two phase of TipText. All text before this delimiter is considered to be the normal tooltip text and all text following this delimiter is considered to be the accelerator binding text.

As you know that vert开发者_开发问答ical bar("|") is quite common character which usually used in a string. if it is a case of this, it shouldn't considered be delimiter and it have real meaning. for example:

label.setToolTipText("<HTML><BODY><LEFT>V1|V2</BODY></HTML>"); Normal use
label.setToolTipText("<HTML><BODY><LEFT>V1V2</BODY></HTML> | ctrl+v"); Use as delimiter

My problem is ToolTipUI don't know how to identify this different now, I cannot change the delimiter "|" to another unusual value for special propose.

Anybody have idea?

Thanks


If you can't use Mark Elliot's suggestion to pass the argument as two separate strings, then something along these lines might either help or make things worse:

  private int delimPosition(String s) {
    int eos = s.toLowerCase().lastIndexOf("</html>");
    return s.indexOf('|', eos+1);
  }

(To be used as a replacement for s.indexOf('|') that I'm guessing you are currently using).

Although I suspect you will probably end up with a significant degree of escalating complexity in this method, once all the corner cases have been worked out. Maybe better to refactor now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜