Deadshot Deadshot - 1 year ago 77
Java Question

JavaFX coordinates inverted on the Y-axis with respect to Swing

Previously, I asked a question comparing the SceneBuilder coordinates with JavaFX's output. I have come to realize that the problem did not lie within SceneBuilder and the exported FXML code; but it is, in fact, a problem with my machine's version of JavaFX. However, I'm still unclear as to why this happens.

In my FXML code, I have the following hierarchy:

<AnchorPane id="rootPane" pickOnBounds="false" xmlns="" xmlns:fx="">
<StackPane id="game">
<AnchorPane id="hud" style="-fx-background-color: rgba(0, 0, 0, 0);">
<Text id="ammo" fontSmoothingType="LCD" layoutX="14.0" layoutY="699.0" strokeType="OUTSIDE" strokeWidth="0.0" text="0" wrappingWidth="111.21875">
<Font name="Brother Deluxe 1350 Font" size="48.0" />
<DropShadow color="#0000007a" height="16.0" offsetY="1.0" radius="5.5" width="8.0" />

This produces the following output from IntelliJ:
Java export with inverted Y coordinates

As you can see, the Y coordinates are flipped, with 0,0 being in the bottom left of the screen. But in SceneBuilder, the output is what I would normally expect:
SceneBuilder preview with proper Y coordinates

If necessary, the full code can be found here.

My question is, why is my JavaFX application producing an interface with 0,0 being at the bottom left instead of the top left, as my research indicates it should be? And if possible, how can I fix this problem?

My operating system is OS X 10.12, El Capitan. My JDK version is 1.8.0_66.

Answer Source

There was a bug with SceneAntialiasing.BALANCED on Mac that flipped the scene. It was filed based on this question and it is already fixed for Java 9 and back ported to recent versions of JDK 8.

The solution is just updating to the latest JDK version if possible.

If not, removing the antialiasing parameter or using SceneAntialiasing.DISABLED works as well.