Scene Builder 2.0 can't load stylesheet from resources/classpath - javafx-2

My FXML file has an attribute stylesheets="styles/Styles.css" specified on the root node. This works fine when the program is launched. However, in Scene Builder 2 the css doesn't load, the console prints WARNING: Resource "styles/Styles.css" not found., the Properties panel doesn't work, and the console further prints stack traces. If the stylesheets attribute is specified with an absolute file: url, then SB works, but I need the url to point to the classpath.

In my case is stylesheet defined like this inside of root element:
<stylesheets>
<URL value="#css/base.css" />
</stylesheets>
In this notation it probable means, that file is searched for relatively from FXML file position.
But you must specify location of loaded FXML file in runtime.
// file = String with FXML file path, loader = FXMLLoader
URL resource = getClass().getResource(file);
loader.setLocation(resource);
I hope, it will help you...
Btw Scene Builder 2.0 is still Early Access version, so there might be some problem too...

Related

Gifs on Sailfish-os

I came here with a little problem, i can't use any local .gif in my code.
I work on Linux with QtCreator and the Sailfish VM to make a Sailfish-os application.
I tried first this example, without any success.
Rectangle {
width: animation.width
height: animation.height
AnimatedImage { id: animation; source: "../images/animatedimageitem.gif"}
}
The execution return :
QML AnimatedImage: Error Reading Animated Image File file:///bla/bla/.....
Same problem with other permissions on the gif and with an other gif.
After some researches I found this page where someone indicate to download a plugin, but Qt declare (I wish i could put a link but i'm new -_-', see comments) that gifs are already support by default.
The plugin was finally unobtainable and I found this Sailfish/bin/plugins/imageformats/libqgif.so in my directories.
So what can i do to show a gif on this damn thing ?
The error you are seeing is probably related to filepaths. Gifs are supported, AFAIK.
Instead of coding the path that way, consider the usage of a resource file to improve portability and platform independence.
Create a new resource file (File -> New File or project -> Qt -> Qt Resource File)
The property editor opens, click Add in the bottom then Add prefix and set a prefix such as / (or whatever you like!)
Click again to select Add files and insert your image
Right-click the newly added image entry and copy resource path to Clipboard
Build -> Run qmake (fundamental to ensure correct compilation)
The path you copied in the clipboard should be of the form:
://PATH_TO_IMAGE.gif
Now, given your QML code, I can guess the image folder is inside source code at the same level as the QML folder. Hence, if you added the .gif file from that folder you would have the following path in the clipboard:
://images/name.gif
This can be prepended with the prefix to obtain the final path. If your prefix is set to /, as we did above, the final string to be set in the source property of your AnimatedImage would be:
"qrc:///images/name.gif"
Obviously, a different prefix or a different path would result in a different final path.
Well..... I just put it on my phone (Jolla) and the gif works well. So this is the VM who doesn't seems to like gifs ...
Thanks for help though,
Psycho.

processXmlResource cannot reach the xml file

I'm trying to replicate this hello world example with Haxe and HaxeUI.
When i compile the project everything seems fine but when i try to execute the swf from browser i have an error like: Cannot access a property or method of a null object reference referred to processXmlResource (in the root folder i have the main.hx and in a subfolder the xml).
Below is the screenshot of the error i get:
Have you modified your applications application.xml (or project.xml) to find the asset in your project root? Or put all your assets in an assets sub folder and let then reference that from you application.xml?
Basically it seems it is not finding your xml resource. This sample might be a good example of a basic project setup: https://github.com/ianharrigan/haxeui/tree/master/samples/hello_world_xml

Groovy resource from classpath not loaded

Good day everyone.
I am using spock framework for testing in my groovy project(IDE - Intellij Idea 12.6). My spock specification class pass filename to groovy object for processing (that file is in classpath for sure), but when i try to get that file this way
def resource = getClass().getClassloader().getResourceAsStream(filepath)
assert resource != null : "No input stream found for path ${filepath}"
def rootNode = new XmlParser().parse(resource)
Then resource == null.
I tried debugging and in Expression Evaluation windows this code getClass().getResource(fileName) returns resource.
I tried to check which classloader used in first case (in class with the code) and in second case (Expression Evaluation window).
In first case classloader was sun.misc.Launcher$AppClassLoader#18dabf1, but in Expression Evaluation window classloader was groovy.lang.GroovyClassLoader$InnerLoader#1e69757 I suppose that's the reason my resource was null.
Can someone guide me about what I am doing wrong and how can I load that resource file ?
UPDATE:
Changed the way resource file was parsed. When filepath - full path to file this works, but if filepath is just file name and that file in classpath then resource == null
UPDATE2:
Change the way resource file loaded, clean up dependencies bit and all is working, I guess yesterday just wasn't my day.
The problem is very likely unrelated to Spock. It's hard to say from a distance what's causing it, but the safest way to read a resource is getClass().getClassLoader().getResourceAsStream() or Thread.currentThread().getContextClassLoader().getResourceAsStream(), depending on the environment.
Not sure what Groovy does when you do new File(resource), as there is no File(URL) constructor (only a File(URI) constructor). In any case, getting a File from a class path should be avoided whenever possible.
This is likely due to the fact that Groovy may interpret the class of the object differently that what you think is happening. See the following other StackOverflow item:
Why does groovy .class return a different value than .getClass()
When the class is wrong, then the ClassLoader may well by the bootstrap loader and getClassLoader returns null.
So instead of using a statement like
def resource = getClass().getClassloader().getResourceAsStream(filepath)
specify the actual class using a statement like
def resource = MyClass.class.getClassLoader().getResourceAsStream(filePath)
worked for me in nearly identical circumstances.
def resource = MyClass.class.getResourceAsStream(fileName)
or if you want the content of the file as String:
def str = new String(MyClass.class.getResourceAsStream(fileName).readAllBytes(), StandardCharsets.UTF_8)
Please note:
MyClass is used, not this.getClass();
In resources you must create the same directory structure as the package of your class, and put the files there;
fileName is just simply the name of the file, without any path;
You must clean and rebuild your project.

ClassLoader.getSystemResource(...).getPath() seems to return wrong path

I'm trying to wrap code that requires two *.db4o data files for easy use. I've added the data files to my eclipse .classpath by placing the files in ${project_dir}/res/ and adding the line:
<classpathentry kind="src" path="res"/>
to my .classpath.
I then defined a default constructor to my wrapper class that takes no arguments but goes and finds the paths to the *.db4o files (the paths are required by the compiled code I'm using to set things up). My approach for getting the paths is:
String datapath = ClassLoader.getSystemResource("resource_name").getPath();
This works great when I debug/run my code in eclipse. However when I export it as a jar, I can see that the *.db4o files are in the jar, as well as my compiled code, but the path returned to "datapath" is of the form:
datapath = ${pwd}/file:${absolute_path_to_jar}!/{resource_name}
Is there something about the resource being inside of the jar that prevents an absolute path from working? Also, why is the behavior different simply because the code and resources live in a jar file? One last note is that while my application is intended for wider use (from PIG, python, etc. code) I'm testing it from Matlab which is where I'm getting the odd value assigned to "datapath".
Thanks in advance for any responses.
getSystemResource() returns URL to resource. If your resource is zipped in a jar file then the URL will point into it (with the "!" notation). getPath() returns the "path" part of the URL, not always an actual file path. URL can be one of many things, not just a file.

wxWidgets wxBitmap

Im trying to create toolBar. I added resource file to the Visual Studio project, then added to that resource png file.
Now the question is how to use it as a icon for the button?
this is my code:
wxBitmap exit(wxT("cross.png"));
and when I run application I have error:
Cant load "cross.png" bitmap from resource. Please check .rc file
thanks for help
First you need to make sure you use the actual name of the resource as defined in your RC file (maybe just "cross" instead of "cross.png", as the error states - check your RC file). Second, you'll also need to make sure you have initialized all image handlers if you haven't already (just call wxInitAllImageHandlers()). Third, you'll need to specify the image format type when you call the wxBitmap constructor, for example:
wxBitmap exit(wxT("cross"), wxBITMAP_TYPE_PNG);

Resources