Custom FXML component (w/ controller) doesn't appear in SceneBuilder's “Import jar” dialog

前端 未结 1 1981
一向
一向 2021-01-22 12:33

I am following this in creating a custom component and importing it. However, when it gets to the Import Dialog after clicking the jar file, it does not appear. When I comment o

1条回答
  •  一个人的身影
    2021-01-22 13:34

    I solved this using the information here:

    http://www.cuchazinteractive.com/blog/custom-javafx-controls-and-scene-builder

    To summarise:

    1. Create an FXML file and a Java class that extends the root node (I gave them the same name)
    2. Change the FXML file to have fx:root as the base node. (will not work without this)
    3. Remove the fx:controller attribute (will not work without this)
    4. Compile and add the jar to scene builder

    However, I have found that if your custom control depends on controls from other libraries, it will fail even if the other library is loaded in scene builder.

    Below is a minimum working example

    FXML:

    
    
    
    
    
    
    
       
          

    Java:

    package my.amazing.controls;
    
    import java.io.IOException;
    import javafx.fxml.FXML;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.layout.AnchorPane;
    
    public class TestControl extends AnchorPane {
    
    
        public TestControl() throws IOException {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("TestControl.fxml"));
            loader.setRoot(this);
            loader.setController(this);
            loader.load();
        }
    
        @FXML
        public void initialize() {
        }
    }
    

    0 讨论(0)
提交回复
热议问题