JavaFX can reference statics, variables, and classes from three sources:

  1. Inside the same file
  2. Inside files in the same directory / package
  3. Inside files from other packages

The first option is pretty simple -- it just works. If you are referencing classes from inside the same file, you just use the name -- classes can be defined before or after references to them. Variables can only be referenced only after (below) where they are defined.

For option two, you do not need explicit imports for .fx files in the same package, provided they all have a proper package statement, and are named the same as the classes they contain. ie, I can safely reference a class MediaTable defined in the same package as long as it is named MediaTable.fx.

If you have other inner classes, or you are pulling from a different package (number three), it pretty much requires a bit of extra work, in the form of an import statement. You should name the import for the file name of the .fx file, not for the specific class contained in a file. For example, if MediaTable.fx contains two classes, MediaTableColumn and MediaTableRow, you will get access to both classes by importing MediaTable.

TODO: above need a bit more detail.  Looks like it may not work, at least when
no class name matches the file name.  
A solution is to import the filename, then import each inner class of interest.

You can also do * imports, as in java. Support for this feels a bit weaker, so it is still recommended to explicitly import each class for custom code.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.