Skip to content

Conversation

@DQinYuan
Copy link

Sometimes we may have a custom control in project, I want it to be managed in Spring :

@Component
@FxmlView
// this custom control may be used in many views, so this scope must be PROTOTYPE
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class CustomControl extends BorderPane {
     //...
}

CustomControl.fxml in the same package:

<fx:root type="javafx.scene.layout.BorderPane" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1">
    <!--......-->
</fx:root>

then we can load this custom control in need:

@Component
@FxmlView
public class SomeView {

    @Autowired
    FxWeaver fxWeaver;
    
    @FXML
    private HBox hbox;
   
    @FXML
    private void initialize() {
        for (int i = 0; i < 10; i++) {
            // customControl object is its' controller and view at the same time
            CustomControl  customControl = fxWeaver.loadCustomControl(CustomControl.class);
            hbox.getChildren().add(fxWeaver.loadCustomControl(customControl));
        }
    }
}

@hrzafer
Copy link

hrzafer commented Dec 22, 2021

@DQinYuan is there a workaround for this? I need this feature too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants