JavaFX layout problems

Discussion in 'Mac Programming' started by jerwin, Dec 4, 2016.

  1. jerwin macrumors 68020

    Jun 13, 2015
    Quite recently, I looked into learning javaFX-- as I had a Swing program that was sort of pushing up against the limitations of that library.

    So... HelloWorld in JavaFX.

    What it's supposed to look like:


    What it actually looks like:

    Screen Shot 11.png
    Anybody know what's going on? (This happens even if the code is pasted in directly from the code listing-- something I try as the last resort when learning to code.)

    Finally, I suppose I should ask-- does JavaFX have a future?
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    I don't use JavaFX, so all I have is a few questions, and a rough idea.

    What OS version?
    What Java version?

    Is this on a Mac with a retina-type display?

    In your screenshot, I measured a Mac window content area of about 600 x 500 pixels. The code in the example has this line:
           primaryStage.setScene(new Scene(root, 300, 250));
    Notice the args 300 and 250 are exactly twice the apparent content area size. To me, this suggests retina-type display handling, where there are 2 linear pixels on the display for each linear point (typographic point, not Cartesian).

    The problem seems to be that the placement (and possibly the scaling) of the content within the Scene is incorrect. It looks off by roughly a factor of 2. This is a rough guess, obtained by estimating the center of the button being at the lower-right corner of the displayed content area.

    After a little googling, it seems that "HiDPI" is the term used by JavaFX. Here's the search terms I used, and some results:
    mac javafx hi dpi

    To me, this looks like a graphics scaling bug. Unfortunately, it could be in any of several places.

    It might be in the version of Java you're using. It might be in the OS version you're using. It might be the particular combination of Java and OS versions, i.e. the bug might only appear when both versions are what you have, and not appear on different combinations of OS and Java.

    Some things I'd try in this situation:

    Try some of the other JavaFX examples and see if they misbehave the same way.

    Try a different version of Java on your current OS version.

    Try a different OS version on this version of Java.

    Look into how JavaFX does graphical scaling (zoom) and/or Hi-DPU, and see if you can add code to the example that alters it. For example, change the scaling in the Scene to 50% and see what happens. Or force Hi-DPI to be enabled.

    Check the Java or JavaFX bug database for reported bugs with default scaling on Mac OS.

    Hard to be certain.

    I noticed the link you provided has a last-modified data of Sep 2013. Things might be different now that JavaFX is an integrated part of the Java 8 download.

    It may even be that older examples won't work right. It could be worthwhile to try finding newer examples, such as ones that specifically target Java 8.
  3. jerwin thread starter macrumors 68020

    Jun 13, 2015
  4. jerwin thread starter macrumors 68020

    Jun 13, 2015
    I apologize. Apparently this bug was fixed in a subrelease of Java, which I hadn't yet installed. Possible as far back as Java8u60. The latest release of Java 8 is 8u112
  5. okieiam macrumors newbie


    Dec 17, 2016

Share This Page