javajavafxscenebuilder

Is there a way to add Subclasses from a certain JavaFX Class in Scenebuilder/FXML?


Following Background: For our project we need to implement the famous german boardgame "Settlers of Catan" with Java and JavaFX. The board consists of 19 hexagonal tiles. To spare some complicated calculations for the nodes (City Spots) and edges (Streets) of the hexagon I wanted to create the board in Scenebuilder as fixed FXML. For the hexagons I use JavaFX-Polygons. But the problem is, that I need much more information in the Polygon-Class (e.g. ressource type, nodes, edges).

Is there a way to create a subclass (Tile extends Polygon) and use this class in Scenebuilder or FXML?

Also I tried to cast the Polygons as Tiles, but didnt work either.

I can provide some code later, if necessary.

Thanks in advance!

I tried importing my class in the beginning of the FXML.

<?import package.Tile?

But it wasnt that simple, sadly.


Solution

  • Looks Like you want to create a custom component for the SceneBuilder.

    Step 1: Create the custom vomponent https://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm

    Step 2: Import the custom component into SceneBuilder https://www.google.com/amp/s/staticfinal.blog/2014/05/21/adding-custom-javafx-components-to-scene-builder-2-0/amp/

    Alternative solution:

    You could create a custom component in plain Java and add it to the fxml scene programatically in your controller.