简体   繁体   中英

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 vertical 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM