Java Look and feel - how to break a dependency on sun.swing.SwingUtilities2
Asked Answered
P

2

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

Porush answered 20/8, 2012 at 14:54 Comment(4)
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.Gingergingerbread
@Gingergingerbread My mum warned me not to "look at the sun". (muses) She did not mention "code" though..Progestin
Ouch... this is the poster child for build time code standards enforcement.Loiseloiter
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 mindThrave
C
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.

Crenulation answered 11/9, 2012 at 21:48 Comment(0)
P
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.

Porush answered 27/11, 2012 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.