Info

Tech entrepreneur, executive, and investor; father of eight children; Googler.

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:

Invoking the wrong dialog unit conversion method

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.

Comments

9 Comments

Post a comment
  1. Richard Osbaldeston #
    April 23, 2007

    I suspect it’s just making an educated guess that something with ‘height’ in it shouldn’t be interchanged with ‘width’. Some of the plural-ized variable names it comes up with when expanding iterator templates can be shocking 😉

    I did dip into their GUI builder the other day and noticed it had ClientProperties for a JLabel that’d let me toggle the HTML rendering on & off – Didn’t know where it’d gotten that from. Still can’t get on with their GUI Builder – I was only seeing what I’d broken remapping .form files to xml and creating an .ijfrom type instead. This’ll let me hack Matisse form files in their xml editor instead of complaining they’re all malformed IntelliJ ones.

    – Richard

  2. April 23, 2007

    Richard: Yeah, I’ve never been a fan of their GUI builder. I use the JFormDesigner plug-in. I’ve not worked much with Matisse as I design my layouts in terms of grids, not related component groups, but I certainly respect it.

  3. April 24, 2007

    Hello Ben, you might want to try MiG Layout. It has a unit “logical pixel” that is DLU but in normal DPI one pixel is one pixel. With MiG Layout you can also set this to be default if you like so that you can write “wmin 100” instead of “wmin 100lp”. You can also use percentages of container or screen which is good if you want to make DPI resistant GUIs. MiG Layout has all the features of FormLayout but also a whole slew more. http://www.miglayout.com.

    Cheers,
    Mikael Grev

  4. April 24, 2007

    Well, if there would be some kind of visually configurable layout manager for the MiG Layout which generates code in IDEA (like for our own, internally used layout manager), then I would like to switch. We don’t like to use “classic” GUI designers, because they are too limited in some aspects and allow to much in others compared to coding.

  5. April 24, 2007

    Thomas, actually there will be very soon. JFormDesigner is a standalone GUI designer that now also exists as a plugin for IDEA and Eclipse. They are currently adding support for MiG Layout and it will produce correct code afaik.

  6. February 8, 2012

    Hello there,I’m also linnaerg Android and thanks for the link. Since I have a smartphone to experiment with, it would be fun if I could communicate to Prop or Arduino through bluetooth.Now I’m waiting for the parts to arrive, will learn some Bluetooth from the Android SDK libraries.

  7. February 9, 2012

    auAk11 zsshkxbyuuaq

  8. October 18, 2014

    Nice weblog here! Also your web site rather a lot up
    fast! What host are you the usage of? Can I get your affiliate
    hyperlink in your host? I desire my web site loaded up as
    fast as yours lol

  9. October 22, 2014

    Hi every one, here every person is sharing such knowledge, therefore
    it’s good to read this webpage, and I used to
    go to see this weblog every day.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS