How can i set application icon in javafx2 - icons

javafx set application ico
when i create java project , add jfxrt.jar
it's right
new Image(getClass().getResourceAsStream("../images/customLogo.png"))
but this in javafx project
it's wrong.
how can i get relative path do this in javafx project.

I think that you should take a look on the Image API and this another link where how to put the icon is answered.
If you were generating a jar, you can use
new Image("/path/to/image")
The path to the image starting with "/", will be an absolute path inside the jar. I strongly recommends go to the Image API to check all the options, is really well documented.
Hope it helps

So what is the exception? Where did you create the project (which IDE). As a general rule never use ..-paths when doing look ups although the might work on the filesystem they e.g. break inside jar-files IIRC.

Related

JavaFX CSS image not rendering

I am working on a Gradle JavaFX project in IntelliJ. My question is essentially "How do I get a background-image URL working for JavaFX in CSS?" for which the answer would be:
.button{
-fx-background-image: url("/image/CloseButtonBlack.png");
}
except that this doesn't work for me. After much experimentation, I have discovered that if I move the file up one level so it lies directly in the resources folder, everything works. Because of this, I believe that the reason the file doesn't display when it lies within the image folder is that the image folder is not marked as a resource folder. If I were not using Gradle, I believe I could fix this just by using IntelliJ's Project Structure -> Modules menu. Since I am using Gradle though, I am thinking that the correct way to fix this would be to write some code in build.gradle so that Gradle knows the image folder is a resource folder. If I am right, what code is it that I need to write to get my background image to display while it lies in the image folder?

Best way to deploy JavaFX app with a lot of images

I am fairly new to java. I have written an application that basically has a 50x50 grid of buttons, with each button opening a specific image related to that button. The images are stored on my file system.
The app works perfectly in Netbeans, each button opens up the correct image.
I would now like to export the app to be able to share it with some people that are interested - however I am not sure what is the best way to do this. I have been googling this for days but haven’t found anything that really answers my question.
What I would prefer is this: The user installs/unzips/whatever the app, and as a result is left with a folder with all the image files (quite a lot of them and around 1Gb in size) and a runnable file, preferrably an .exe to run the program.
What would be the best way to achieve something like this?
At first I was thinking about including all the image files in a runnable JAR. The problem with this approach is that I would have to rewrite my code, as right now my code uses java.io.File to fetch the images and to my knowledge this doesn’t work inside a JAR. Also I would much prefer an .exe instead of a JAR.
Any help will be greatly appreciated!
as right now my code uses java.io.File to fetch the images
Are you saying that you use java.io.File to get a listing of available images or that you're using it to read an image?
If you need a list of images or resources inside a jar take a look at "How to list the files inside a JAR file?"
To read an image from inside a jar using JavaFX, you just need to get the URL to the image:
import javafx.scene.image.Image;
URL url = getClass().getResource("/path/inside/jar/myimage.png");
Image image = new Image(url.toExternalForm(), true);
As to the best way to deploy that app ... I would say that a 1GB app is a beast. Could you host the images on a web server and have the app lazily fetch the images as they need to be displayed?

Java app deployment and installer parameters

I am using javapackager for making installer from .jar. I need to give some params to my installer(splash screen icon, remove version from app name etc), that can't be given directly by javapackager. Instead javapackager has an paramfile option, but I don't know how to use it, and what structure will it have?? Can anyone help me??
it is a java properties file. You can look in https://github.com/Debian/openjfx for the parameter you want to override and then set it in the properties file.

Qt how to access resources

Qt Creator give the possibility to attach some resource to the project.
I created in the project directory a folder called: Images. inside i have the file splash1.jpg
I created then the Resources file and attached the file as shown in the following figure:
Which is now the correct way to access from code such a file?
I tryed
QPixmap pixmap( "Images/splash1.jpg" );
QPixmap pixmap( "./Images/splash1.jpg" );
but none of them worked.
if i put just ./Images/splash1.jpg work at least if i compile by hand with qmake and make because has the correct path at runtime but no way to make it work within qt creator
Any idea??
Cheers,
Qt5 resources explains all you need. You have to put the colon before the path in the source tree. You also have placed a prefix, so :/Images/Images/splash1.jpg. This will give you a path.
If you need a URL, then use the qrc: scheme.
The correct way to load with Qt resources is: :/Images/Images/splash1.jpg.
What you could also do, is assign an alias to the resource. This way you don't need the .jpg: :/Images/splash
You can use ":/prefix/name of your image".

Flex - Source Size vs. Compile Size

Could you explain why a Flash Builder source folder - no larger than 2 MB - compiles into a SWF exceeding 15 MB with debugging turned off (exported release build)?
There is only 1 embedded image at about 93k - no other images. The application is not that complicated, basically calls are made to a MySQL db to display information, as well as store information. I have used drop shadows and borders, but all standard to Flash Builder. Some custom classes and one custom skin.
Thank you...
Here is listing of the files:
.DS_Store
mx_4.5.1.21328.swz
Main.html
playerProductInstall.swf
Main.swf > 15 MB
rpc_4.5.1.21328.swz
amf_config.ini
services
assets
skins
charts_4.5.1.21328.swz
spark_4.5.1.21328.swz
framework_4.5.1.21328.swz
sparkskins_4.5.1.21328.swz
gateway.php
swfobject.js
history
textLayout_2.0.0.232.swz
This seems pretty large to me.
When you say "Debugging Turned Off" what does that mean? Did you export a release build? Or did you just press the "play" button to run your code instead of the "Debug" button?
Do you have the Flex Framework linkage type set to RSL (AKA External) or Merge into Code?
Are you using an external libraries (SWC)? A framework, such as RobotLegs or Swiz, could add to the size of the SWF; but will probably not be located in the source folder.
Well, well...thought I'd revisit this since I found the problem - a font in a css file with embed set to 'true'. This font wasn't even being used, so I removed it and the css file completely (not in use either). They probably got inserted way early in the project. Code now hovering around 1 MB and less than that for the export build. Hope this helps someone. Cheers!
Flex is a collection of ActionScript classes and components, so when you build an app based on Flex, some of these classes get embedded into your application.
Something as simple as a <s:Button means that the byte code of spark.components.Button has to be included into your application along with your custom code, it's not part of the runtime.

Resources