18

I am maintaining some code the implements a customized Look and Feel in Java. While doing a recent upgrade of Java version (for other reasons) I found that the Look and feel broke due to a field not found on

sun.swing.SwingUtilities2.BASICMENUITEMUI_MAX_TEXT_OFFSET;

This is in a class that is closely based on BasicMenuItemUI.layoutMenuItem() circa Java 6u02 (here's the source). I have found that Oracle have re-factored their code to include a MenuItemLayoutHelper in the new target version I am using, Java 6u31.

I could just use the MenuItemLayoutHelper but that doesn't solve the problem it just puts it off until the next time the Java internals are changed around. Therefore, I have discounted this as a solution.

I am after some advise on how to achieve a left to right layout similar to BasicMenuItemUI without needing to know the parents' maximum text offset (removing the bad dependency on sun.swing.SwingUtilities).

Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
Petec
  • 271
  • 1
  • 6
  • 17
    probably not an option to grab the person that introduced that dependency, lock her into a room until all is fixed :-) At the end of the day, there isn't much to do ... except ... cough .. c&p, ehh, I mean look at the sun code and implement a refactored version. – kleopatra Aug 20 '12 at 15:14
  • 9
    @kleopatra My mum warned me **not** to "look at the sun". (muses) She did not mention "code" though.. – Andrew Thompson Aug 21 '12 at 00:12
  • Ouch... this is the poster child for build time code standards enforcement. – Gus Aug 27 '12 at 23:49
  • 7
    So basically you want to use java code without dependencies of java code. Short answer: You cannot. It is expected that new version of java have new code and refactors. You have to change your mind – albfan Aug 28 '12 at 15:24

2 Answers2

4

As albfan said, you can't. You either have to depend on the code, copy the class and use it in your program, not use it at all and use a third party library, or not use that feature.

albfan
  • 12,542
  • 4
  • 61
  • 80
Coupon22
  • 395
  • 8
  • 24
2

Ok it may have been a while but I figured out I could just use my own constant instead of sun.swing.SwingUtilities2.BASICMENUITEMUI_MAX_TEXT_OFFSET as long as it was used consistently in the offending code. By no means an ideal solution.

On the upside bad imports from sun packages has gone into the coding rule checks.

Petec
  • 271
  • 1
  • 6