FXMLLoader & BuilderFactory

Daniel Zwolenski zonski at gmail.com
Wed May 29 15:25:23 PDT 2013


When you say 'instance' what do you mean? A controller or a node or something else?

A controller can be notified when it is initialized (and all the associated nodes will be initialized by this point):

http://docs.oracle.com/javafx/2/api/javafx/fxml/Initializable.html

Does that give you the hook ins you need?

On 30/05/2013, at 8:03 AM, Florian Brunner <fbrunnerlist at gmx.ch> wrote:

> Hi,
> 
> I'm experimenting with FXMLLoader. Is there a way to get notified, when an instance gets created?
> 
> I tried to work with a wrapper class for BuilderFactory, like this:
> 
> public class WrapperBuilderFactory implements BuilderFactory {
> 
>    private final BuilderFactory builderFactory;
> 
>    public WrapperBuilderFactory(BuilderFactory builderFactory) {
>        this.builderFactory = builderFactory;
>    }
> 
>    @Override
>    public Builder<?> getBuilder(Class<?> type) {
>        Builder<?> builder = builderFactory.getBuilder(type);
>        return new WrapperBuilder<>(builder);
>    }
> 
>    private static class WrapperBuilder<T> implements Builder<T> {
> 
>        private final Builder<T> builder;
> 
>        public WrapperBuilder(Builder<T> builder) {
>            this.builder = builder;
>        }
> 
>        @Override
>        public T build() {
>            T t = builder.build();
>            doSomething();
>            return t;
>        }
> 
>        private void doSomething(){
>            // do something
>        }
>    }
> } 
> 
> and then call:
> FXMLLoader loader = new FXMLLoader();
> loader.setBuilderFactory(new FXMLControllerBuilderFactory(loader.getBuilderFactory()));
> 
> 
> But it seems that BuilderFactory.getBuilder usually returns null, which gets treaded completely differently (instance created at XML start tag) than when a Builder gets returned (instance created at XML end tag).
> 
> Is there another way to get notified when an instance gets created?
> 
> Otherwise I will file an enhancement request.
> 
> Kind regards,
> Florian
> 


More information about the openjfx-dev mailing list