1

We have multiple GUI project based on JavaFX. Our goal now is to refactor a lot of these GUI's and to extract common views and source code and make this common code available through libs (bundle jar's). I currently have the problem that I have a View which displays log files and which is included via an FXML in the main view

<fx:include fx:id="logFileView" source="./sub/LogView.fxml"
    maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
    minWidth="-Infinity" prefHeight="600" prefWidth="1000"
    style="-fx-background-color: rgba(0, 0, 0, 0.0);"
    StackPane.alignment="CENTER_RIGHT" />

The LogView.fxml incorporates it's controller

fx:controller="auv.e4.application.analyser.controller.sub.LogViewController"

but this LogView.fxml is now placed in a common lib (bundle jar) and should be accessible by any of our GUIS's

We have like 50 different views which are structured this way and I would prefer using the FXML this way.

Another problem is the common lib will be bundle project (otherwise the RCP GUI can*t resolve them as dependencies) which makes using absolute paths impossible (Which is alo not a good practice). The GUIs are RCP based GUI's which use JavaFX for rendering.

My question is now how do I reference the LogView.fxml from an another project from inside an FXML (with fx:include) ? Is this possible ? If not what kind of restructuring should /can be be done ?

Westranger
  • 1,308
  • 19
  • 29
  • So is this an e4 RCP using e(fx)clipse? If so you might want to include that in the tags so that the right people see this question. – greg-449 Oct 20 '16 at 15:10
  • You should be able to access the fxml file by specifying its full path relative to the classpath (begin the path with a leading `/`, i.e. `source='/com/mycompany/libs/etc/LogView.fxml'`) and I think that will work as long as the jar is on the classpath. If not, note that `FXMLLoader` has [`setClassLoader(...)`](http://docs.oracle.com/javase/8/javafx/api/javafx/fxml/FXMLLoader.html#setClassLoader-java.lang.ClassLoader-) and `setDefaultClassLoader(...)` methods. I've never used those methods and documentation is scant, so you might have to dig around a little: hope that helps though... – James_D Oct 20 '16 at 15:11

0 Answers0