gluonhq / scenebuilder

Scene Builder is a visual, drag 'n' drop, layout tool for designing JavaFX application user interfaces.
https://gluonhq.com/products/scene-builder/
Other
727 stars 218 forks source link

Can't open fxml that contains "fx:include" #512

Open HendrikH01 opened 2 years ago

HendrikH01 commented 2 years ago

SceneBuilder fails to to open fxml files that contain an “fx:include” tag, which is used to nest different fxml files.

<StackPane prefHeight="150.0" prefWidth="200.0" BorderPane.alignment="CENTER">
          <children>
                  <fx:include fx:id="canvas" source="canvas.fxml" />  <-- crashes here

This code is completely valid and runs fine with JavaFx 16, but SceneBuilder can’t open the fxml unless I remove the line.

Oliver-Loeffler commented 2 years ago

Hi @pythonSux,

SceneBuilder should be able to handle includes. To investigate the issue, can you pleas provide the content of the mentioned canvas.fxml file? I'd like to investigate the issue. It would really be helpful if you could attach both FXML files.

HendrikH01 commented 2 years ago

https://hatebin.com/inbqtbtdcm

this is the one that gets included: https://hatebin.com/urpfwvtbrb

I have it separately so I can use a different controller class and don't have to stuff all the event handlers into one class

Oliver-Loeffler commented 2 years ago

Thanks, I'll play with it and see what I can do.

Oliver-Loeffler commented 1 year ago

Hi @AlmasB, could you please assign this one to me?

Oliver-Loeffler commented 1 year ago

Hi @pythonSux ,

it seems there is a non-standard control included in the canvas fxml file. This control is imported via <?import com.hhuebner.autogp.ui.widgets.InformationLabel?> and used within the FXML element <InformationLabel/>.

By default, Scene Builder seems to crash as it cannot instantiate this custom element. I cannot say how it should behave, this is something I have to figure out. Ideally, if the FXML loader detects a non-standard control which is not available to classpath, it should notify the user. Not sure if it makes sense to replace then the representation of the non-standard control with e.g. a red rectangle or so.

Technically, the way how the include mechanism is built in the proviced FXMLs, the thing is fine.

Oliver-Loeffler commented 1 year ago

The problem is indeed the custom control inside the canvas file. You'd have to add this as custom control to Scene Builder using the JAR/FXML Manager. If the control has been added, the import is the problem. Scene Builder 18 shows a proper Exception dialog and the most important detail is shown at the end of the stack trace.

Stacktrace

This is exactly what is mentioned in canvas FXML header.

<?xml version="1.0" encoding="UTF-8"?>

<?import com.hhuebner.autogp.ui.widgets.InformationLabel?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.layout.*?>

I've tested the behavior with org.controlsfx and here it works to (a) include a custom component inside the container and (b) use a custom element in an included FXML. So this should run fine with 18 and 19 as long as the custom control has been added to Scene Builder. Can you please check if your SB16 instance has some customization?

What remains is to make the message to the user more clear so that this error is easier to detect. I've started a discussion #575 to figure out, what could be the best way to handle such situation.

My proposal here is, that I'll rework the message dialog so that the issue of missing libraries/controls can be identified more easily.

Oliver-Loeffler commented 1 year ago

Related issues:

253 (FXML wont load when unknown user data is referenced)

281 (ClassDefNotFoundError when importing custom component)