JavaFX 11: IllegalAccessError when creating Label

You are already giving an explanation of your issue:

I have not modified any VM options.

Since JavaFX 11 is not part of the JDK anymore, you have to use the JavaFX SDK (as you are doing) from here, or alternatively use Maven/Gradle to retrieve the JavaFX modules from Maven Central.

Then you need to add the SDK as a library, so IntelliJ can find the JavaFX classes.

But once you have done that, and given that the JavaFX jars are modules, you still need to do two things:

  • Make the JavaFX modules available to your module-path
  • Define which modules do you add to the project

Based on your IntelliJ output, it is adding by default javafx.graphics and javafx.base:

--add-modules javafx.base,javafx.graphics

-p /usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.base.jar
:/usr/lib/jvm/javafx-sdk-11.0.2/lib/javafx.graphics.jar

(note that -p is the same as --module-path)

This explains why your project runs in the first case, when you don't have a control added to the scene, just the StackPane, that belongs to the javafx.graphics module, but fails with the posted exception when you add the Label, that belongs to the javafx.controls module.

This has been said a number of times: you need to set the required VM options for your project.

Start by reading the documentation at https://openjfx.io/openjfx-docs/, including the IntelliJ doc, section Non-modular projects for your IDE. And read the part 4. Add VM options.

VM Options

So click on Run -> Edit Configurations, and add:

-p /usr/lib/jvm/javafx-sdk-11.0.2/lib --add-modules javafx.controls

Apply, and run, the issue will be solved.