简体   繁体   English

Java Swing 中的小问题

[英]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.我已经定义了 class ToolTipUI,它扩展了 BasicToolTipUI 以建议绘制 swing 组件的 TipText,我使用分隔符“|”(竖线)来区分 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 "|"我的问题是 ToolTipUI 现在不知道如何识别这个不同,我无法更改分隔符“|” 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:如果您不能使用 Mark Elliot 的建议将参数作为两个单独的字符串传递,那么这些方面的内容可能会有所帮助或使事情变得更糟:

  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). (用作我猜您当前正在使用的s.indexOf('|')的替代品)。

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.现在也许更好地重构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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