Custom Components in Scenebuilder 2.0 - javafx

In Scenebuilder 1.1, you could import an entire custom component as a whole.
In 2.0, however, it is importing the component as separate pieces (Container and nodes). Since my custom component relies on being unified to work with its controller and IDs, this breaks it.
Is there anything I can do as of yet? I'd really like to be able to use Java 8 and Scenebuilder 2.0 for its DatePicker. If a full stable release is right around the corner, perhaps I can wait. I'd preferably want to avoid hacky solutions.
Any ideas?

I have only found one way to deal with this kind of back-compatibility: building my own scenebuilder.
It is officially open source so you can check it out with mercurial on bitbucket for instance.
Then you build it and modify it to put all your custom components and dependencies in the same classpath for one unique classloader.
Check the class named FXOMLLoader, it is where the classloader is used, my fix was to explicitly only use one classloader for all components and adding a few repertories with my deps inside to the classpath for it to work.
I have used Jar Class Loader library to do so, and it works pretty well. This is pretty hacky though.

Related

Gluon Client Maven Plugin: Which type of classes should be specified under 'reflectionList' configuration

In the official documentation of Gluon Client maven plugin, the 'reflectionList' section is explained as
List of additional full qualified classes that will be added to the default reflection list, that already includes most of the JavaFX classes.
Tbh, it doesn't clearly explain what type of classes should be added in 'reflectionList'. In a pom.xml file of a gluon sample some of the classes in that project are not specified.
So, what kind of classes do we have to specify in 'reflectionList'?
You only have to add classes which are loaded via reflection. This happens for example when you are using FXML. It's mostly a try and error game unless you are following a more systematic approach and use the GraalVM native-image agent.
In most cases, controllers for FXML views created in Scene Builder. In the FXML file you specify what class should be a controller for a view generated from this file, and in that controller class you put fields and methods which are linked to elements in FXML. Sometimes, unfortunately, if you use a certain JavaFX widget in FXML you will also have to specify it on the reflection list (happened to me with javafx.scene.control.TitledPane).
There is way to make it more fine-grained and specify certain methods instead of all classes, but I wouldn't recomment it. Please take a look here for details: How to solve fxml loading exceptions in compiled JavaFX project using GluonHQ client, Native Image and GraalVM?
My solution is to keep FXML simple and enrich it with additional styles, register methods on actions (unless they are straightforward, like onClick), etc., in the code, so that I don't have to deal much with reflection.

Scene Builder - Custom Control Reuse

I've been at this problem trying to find workarounds for weeks now and I am starting to give up. I must be doing something fundamentally wrong. Anyway, this is my situation. I have previously made a neat little program using JavaFX but have now discovered Scene Builder and want to build it all again using this tool. The project includes several components that are frequently reused such as the one below. This is made up of a label, a slider, a text field and another custom component, an InfoIcon.
I have understood that the done thing is to import the custom component (the InfoIcon) as a .jar file into Scene Builder when building my SliderVariable as I call it. This works great and I can run a small demo of my SliderVariable from within Eclipse by creating a main method, a scene and making a SliderVariable in this scene. As mentioned this works great. Importing or Including the InfoIcon does not do what I want (I don't think) because then I cannot easily make changes to the InfoIcon (or its controller) and update my SliderVariable and then see the effects in the final product.
The problems arise when I want to take it one step further and in turn use my SliderVariable in Scene Builder. I do as with the InfoIcon. I export my slider variable to a non-executable jar and then import it into Scene Builder. Here Scene Builder complains that it cannot find any UI components and thus fails to import it. I have discovered that this is because when I export the SliderVariable as a jar it does not also package its dependencies meaning the InfoIcon doesn't get bundled with it and that the compiler cannot find this component as I try to use it.
I have tried to solve this with FatJar which I cannot get working (and it seems like it is not in use any more). I have tried Maven where I couldn't import the Maven project dependency of the InfoIcon in the FXML of the SliderVariable. Finally I have also tried simply not importing a jar but instead including the source code of InfoIcon in a separate package of SliderVariable but then I couldn't import it into my FXML. I am desperate. What do people normally do if they want to reuse custom components with their own controllers in Scene Builder? Is this even done? Should I just give up :'(?
This unwieldly post must be highly confusing but I do not know how to make it clearer. Any sort of response would be greatly appreciated and if you do not believe this forum is the right place to post something like this (which it probably isn't) please point me to someplace else where I am more welcome.
Many thanks.
EDIT 1: I have now added a folder in my project called Dependencies. In here I put a copy (not a reference to) my InfoIcon.jar.
I then add this .jar file to my Build Path and remove the old one. I then enter SceneBuilder and reimport the InfoIcon jar but this time from the Dependencies folder I just created. At this point the small project test I've made still runs fine. I then export as JAR file with the following settings and hit finish.
I then try to import it into Scene Builder and Scene Builder tells me it cannot find any UI components.
EDIT 2: Should I select these items?
Note that the jar file is in Dependencies but also in Referenced Libraries (which is not visible here). This type of selection makes it so that Scene Builder can find and Import the InfoIcon but not the SliderVariable.
When you export InfoIcon, you can simply select the packages and classes related to it in the Eclipse's package explorer (or other similar explorer views), and choose export.
Similarly, when you try to export SliderVariable control, you need to choose everything you have selected in InfoIcon, on top of other files that are needed by SliderVariable control itself.
If InfoIcon is imported into SliderVariable project as a JAR file, then you would need to manually select that JAR file during the export of SliderVariable.

Unable to use playn JSON classes in Eclipse

I'm not able to access the playn.core.json.* classes inside eclipse even though everything else works in general. I have used this http://code.google.com/p/playn/wiki/GettingStarted in setting up my eclipse project.
However the following classes are visible -
JsonImpl
JsonParserException
JsonSink
JsonTypedArray
JsonWriterException
When I go to the referenced libraries in Eclipse, I can see playn.core.json and
can see all classes inside it. I'm just not able to use them inside my
code.
Thanks!
Just saw the samples.
You're supposed to use the interface Json.Object/Json.Array.
Use PlayN.json().createObject() to create a new Json.Object instance, and PlayN.json().createArray() to create a new Json.Array instance.
Make sure you have statically imported playn.core.PlayN.*

Can't find compiled resource bundles

I am using Adobe Flash Builder 4.
I've run into this issue with my latest project, but I was able to re-create it with an almost empty project.
Here is what I've done.
Created a new Flex Project
Created a locale/en_US folder within this project.
Added a class that extends SparkDownloadProgressBar. All this class does is attempt to create a Label.
When I try to debug this application, I get the following error.
Error: Could not find compiled resource bundle 'components' for locale 'en_US'.
at mx.resources::ResourceManagerImpl/installCompiledResourceBundle()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:340]
at mx.resources::ResourceManagerImpl/installCompiledResourceBundles()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:269]
at mx.resources::ResourceManagerImpl/processInfo()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:387]
at mx.resources::ResourceManagerImpl()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:122]
at mx.resources::ResourceManager$/getInstance()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManager.as:111]
at mx.core::UIComponent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:3728]
at spark.components.supportClasses::TextBase()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\supportClasses\TextBase.as:154]
at spark.components::Label()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Label.as:384]
at Preloader()[C:\SVN\Games\Social\Test\src\Preloader.as:21]
at mx.preloaders::Preloader/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\preloaders\Preloader.as:253]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:1925]
at mx.managers::SystemManager/initHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2419]
The Flex Compiler/Additional Compiler Arguments section does contain "-locale en_US", but I do not want to just remove this as I am planning to have this load different property files based on the localization region at run-time and how I understand it, I will need to add each locale that I am planning to use on the compile argument line.
I am at a loss as to how to attack this problem. If you need anymore information from me to help with this, I will be more than happy to provide it. Thanks ahead of time for the help!
This might be caused by the fact, that Preloader loads the actual framework, so you can't use the Flex's classes until it loads. Use standard TextField for it and it should work fine.

IDE does not treat mx:Module descendants as Modules?

I'm playing with Modules and they work as advertised: the module swf's ares
built and deployed in the output directories automatically.
My problem is that if I use descendants of mx:Module, the IDE does NOT do all
this nice work for me. I've listed the module in the Flex Modules section of the
project properties, but still nothing.
I'm going to end up repeating a lot of code in each module (to fulfill an
interface) if I cannot figure out how to make the IDE do its thing.
Any ideas?
Right click on your project, go to properties and there's a Modules sections. You can add any classes that extends Sprite.

Resources