When I code Java Swing UIs, I often use Karsten Lentzsch’s excellent JGoodies Forms library to scale my pixel measurements in accordance with the font DPI setting of the underlying operating system (e.g., to properly support Windows’ “Large Fonts” setting). This is done by employing a symbolic measurement unit called a “DLU” (dialog unit) in place of pixels at design-time and then converting the DLU value to a pixel value at run-time.
An unfortunate aspect of the library’s design is that I have to invoke separate methods for converting the units along the X-axis and Y-axis (i.e., I invoke Sizes.dialogUnitXAsPixel and Sizes.dialogUnitYAsPixel). This lends itself to many a subtle bug.
To my amazement, my trusty IDEA was once again one step ahead of me:
Notice in the overly-small screen-shot above that I’m passing a constant containing the word “HEIGHT” into a method that’s expecting a unit value along the X axis. I’m not sure what algorithm IDEA employs to figure this out, but I say again, wow.
Once again, money well spent.