Skip to content

Commit 6ce3783

Browse files
committed
fix: UI loaded from fxml file now correctly loads Image tags, closes #1343
1 parent 2acffc4 commit 6ce3783

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

fxgl/src/main/kotlin/com/almasb/fxgl/app/services/FXGLAssetLoaderService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ private class UIAssetLoader : AssetLoader<UI>(
785785
val controller = (params as UIParams).controller
786786

787787
params.url.openStream().use {
788-
val loader = FXMLLoader()
788+
val loader = FXMLLoader(params.url)
789789
loader.setController(controller)
790790
val root = loader.load<Parent>(it)
791791
controller.init()

fxgl/src/test/kotlin/com/almasb/fxgl/app/AssetLoaderServiceTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.almasb.fxgl.test.InjectInTest
1717
import com.almasb.fxgl.test.RunWithFX
1818
import com.almasb.fxgl.texture.getDummyImage
1919
import com.almasb.fxgl.ui.UIController
20+
import javafx.scene.image.ImageView
2021
import org.hamcrest.CoreMatchers.*
2122
import org.hamcrest.MatcherAssert.assertThat
2223
import org.junit.jupiter.api.Assertions.*
@@ -321,6 +322,21 @@ class AssetLoaderServiceTest {
321322
assertThat(ui.root, `is`(notNullValue()))
322323
}
323324

325+
@Test
326+
fun `Load UI with image element`() {
327+
val controller = object : UIController {
328+
override fun init() {
329+
}
330+
}
331+
332+
val ui = assetLoader.loadUI("fxml/test_ui_with_image.fxml", controller)
333+
334+
val imageView = ui.root.lookup("#imageView") as ImageView
335+
336+
assertThat(imageView, `is`(notNullValue()))
337+
assertThat(imageView.image, `is`(notNullValue()))
338+
}
339+
324340
@Test
325341
fun loadCSS() {
326342
var css = assetLoader.loadCSS("test.css")
848 Bytes
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.image.Image?>
4+
<?import javafx.scene.image.ImageView?>
5+
<?import javafx.scene.layout.Pane?>
6+
7+
<Pane xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
8+
<ImageView id="imageView">
9+
<Image url="@test.png"/>
10+
</ImageView>
11+
</Pane>

0 commit comments

Comments
 (0)