1

I see that there are many posts about this, some slightly recent, some much older. Nonetheless, I would like to share my own experience because I am facing this issue and I cannot seem to find a solution.

First of all, the context :

  • I use Intellij IDEA Community Edition 20018.2.2 from 21st of August 2018
  • I use Scene Builder from GLUON, version 8.5.0 (latest as of this post)
  • I use the JDK & JRE 64 bits version 8.181 (latest as of this post)

The situation: I am writing a chat app. I have a MainView which is divided into 3 components. In order to split the UI logic, these 3 components are as followed :

  1. The ConversationView which displays the list of conversation ;
  2. The ActiveConversationView which displays the currently selected conversation, whith all the messages ;
  3. The ToolBarView which sits on the top of the window and displays some icons with specific actions.

Working individually on these components is OK, both integrated Scene Builder (in Intellij) and GLUON Scene Builder open the FXMLs and display the content.

As you will understand, the MainView FXML is very straightforward :

<fx:root minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="1280.0" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">
    <children>
        <ToolBarView fx:id="toolBarView" minHeight="-Infinity" minWidth="-Infinity" prefHeight="72.0" prefWidth="1280.0" AnchorPane.bottomAnchor="648.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
        <ConversationsView fx:id="conversationsView" minHeight="-Infinity" minWidth="-Infinity" prefHeight="648.0" prefWidth="320.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="960.0" AnchorPane.topAnchor="72.0" />
        <ActiveConversationView fx:id="activeConversationView" prefHeight="648.0" prefWidth="960.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="320.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="72.0" />
    </children>
</fx:root>

As a precision, I work using the MVVM pattern, so all views have their corresponding view models, down to each cells in each lists.

After some work, I wanted to go back to the MainView layout file in order to make some adjustments and there I have my issue:

Caused by: java.lang.ClassNotFoundException: myproject.view.main.activeconversation.ActiveConversationView

Since the GLUON Scene Builder failed to load my layout, I attempted do it with the integrated Scene Builder and it works perfectly.

I whish somebody can help me understand why GLUON's Scene Builder won't open my MainView. I know I can keep using the integrated Scene Builder, but it's slow, and laggy and layout is too constraint.

I even tried to add manually the components's relative FXML file but I got the following error :

enter image description here

Finally, as a last point, each of these components do not contain nested custom controls. So, only the MainView contains the 3 custom controls. And each of these components constructor relies on the same code (e.g. the ConversationView):

public ConversationsView() {
        this.viewModel = new ConversationsViewModel();

        final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ConversationsLayout.fxml"));
        fxmlLoader.setClassLoader(getClass().getClassLoader()); // I read on another SO post that this could solve the problem, but it does not.
        fxmlLoader.setController(this);
        fxmlLoader.setRoot(this);

        try {
            fxmlLoader.load();
        } catch (final IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
Mackovich
  • 3,319
  • 6
  • 35
  • 73
  • Have you exported your custom controls to a jar and added that jar into Gluon SceneBuilder? – purring pigeon Aug 31 '18 at 14:35
  • Thank you for your suggestion. I have attempted to do so. However, in the dialog to select which controls I want to import, none of them are available: only those which are not custom. It does make sense as I cannot import the FXML directly (see picture in OP). Plus, if I were to modify these layouts, repackaging and re-importing them each time sounds like a hassle, doesn't it ? – Mackovich Aug 31 '18 at 18:32
  • That's how we do it - or you can hook it up to a repository, so it pulls from there as well. To have it import, the control needs a no args constructor I believe. – purring pigeon Aug 31 '18 at 18:41
  • I see and I understand. After verification, none of my three components have constructors with arguments. Check the end of my OP, this how each constructors look like: loading FXML and creating view models. – Mackovich Aug 31 '18 at 18:49
  • These aren't exactly the same thing, but this may be related to this question that I just asked: https://stackoverflow.com/questions/64600828/scenebuilder-wont-load-my-custom-control-which-references-another-custom-contro If you ever came up with a solution for this one, does it apply to my question as well? – NateW Oct 29 '20 at 23:54

0 Answers0