JavaFX CSS image loading on Linux - java

I would like to load an image as a background image in a css file included by my fxml file.
I am certain that the CSS is working, because I can change the background color for instance, but when I try :
GridPane{
-fx-background-image: url('wallpaper.jpg');
}
I always end up with this warning :
WARNING: Error loading image: file:/home/user/IdeaProjects/btnv2/ws_client/out/production/ws_client/wallpaper.jpg
Now the weird thing is that the image path displayed by the error is correct, and when my friend pulled the project the image displayed correctly for him with no error.
I am running Arch Linux and he's on MacOs, i figured that might have something to do with it.
This is the production project structure :

Related

unable to upload image when run my code in github actions

I need to upload an image using selenium webdriver and run it locally and on GitHub actions using java language :
I added the image in the folder in my project
get absolute path to my image
used sendKeys() to send the absolute path of my image
when running code locally works fine but when running it on GitHub Action returns an error "org.openqa.selenium.InvalidArgumentException:"
File file = new File("src/main/resources/UploadImage/MyImage.png");
imageUploadChooseFile.sendKeys(file.getAbsolutePath());
Screenshot for the error :
Screenshot for the error

How to set objects path to the app directory

I compiled my app with image objects, which located in my computer
ImageIcon background = new ImageIcon("D:\\pictures\\background.png")
It seems to be unseen , as soon as I change location of my pictures. Then, I copied those images in app folder and I don’t know how to set path for them. The Idea is to set path of the images for JavaFx application, which should locate at the same folder. And when my app is in someone’s computer,system should know that the pictures inside application folder , wherever this folder locates.
Thanks in advance
Here I’ve made some changes based on advice.
I added my images directly to the project folder by creating new packages resources.images and dragging images in it.
Then I created BufferedImage img; and set path for every image I needed
Image bg;
Image fg;
Image object;
img = ImageIO.read(getClass().getResource(“resources/images/img1.png”));
bg = img;
img = ImageIO.read(getClass().getResource(“resources/images/img2.png”));
fg = img;
And so on ...
Then I drew these images through paintComponent.
And everything seems to be fine, it works after compiling in my environment as it should , but as soon as I create JavaFx app and run .exe file , images don’t display, just empty frame.
:( help me deal with this guys. Thx
If I understand the question correctly, you want to use images that you define and then use those images on whatever computer your app is running. If that is what you are trying to do, I suggest the following:
Create a package called for instance 'images' in one of your source folders.
Access it with
ImageIO.read(YourMainClass.class.getClassLoader().getResource("images/imagename.png"));
(ImageIO.read is just an example of a way to load an image, use whatever you like.)
If you export your app correctly, the images should be put into the jar and be accessible for your application on any device.

Libgdx Can't Load Text Written in Overlap2D

I am attempting to create a game in libgdx using the tool overlap2d, and everything works fine except one key thing: every time I add text to the scene, I get an error stating that it can't find the corresponding font file. I have the file, I've made sure it's spelled right, and I've tried running this with it in my assets folder and just about every other folder in my project, but it just won't work. What do I need to do or where do I need to put this for libgdx to be able to find my font?
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: File not found: freetypefonts\Calibri.ttf (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:602)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.<init>(FreeTypeFontGenerator.java:90)
at com.uwsoft.editor.renderer.resources.ResourceManager.loadFont(ResourceManager.java:319)
at com.uwsoft.editor.renderer.resources.ResourceManager.loadFonts(ResourceManager.java:312)
at com.uwsoft.editor.renderer.resources.ResourceManager.loadAssets(ResourceManager.java:205)
at com.uwsoft.editor.renderer.resources.ResourceManager.initAllResources(ResourceManager.java:100)
at com.uwsoft.editor.renderer.SceneLoader.<init>(SceneLoader.java:63)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:21)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:146)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:123)
Try opening the project in editor again, and pressing export again, the ttf file probably did not get exported first time around.

JavaFX SceneBuilder ImageView not working

I need to create a GUI with SceneBuilder. I added an ImageView to my interface and set the path to my image correctly. The image is showing inside SceneBuilder, but when I run my application, the image is not there.
I put the image inside "img/placeholder.png", and then directly into my root directory. Doesn't matter where I put it, it isn't working.
The path to my gui.fxml file:
/src/gui/gui.fxml
The path to my image file:
/placeholder.png
Can anybody help me please?
There's an easier solution to your problem, without the need of adding or removing any code.
Once you had created an ImageView control in Scene Builder and chosen an image from your computer, select the "gear" icon right beside the ellipses button and select "switch to absolute path".
Image will then automatically appear when you run the code.
Another solution in some particular context (maven related)
Given /src/main/resources/foo/gui.fxml and /src/main/resources/foo/img/foo.png, if you create an image view in SceneBuilder and set the image to foo.png, the url reads #img/foo.png. Unfortunately the image does not show in the application. If you change the image url to #/foo/img/foo.png then the image won't show anymore in SceneBuilder but it will show in the application.
SceneBuilder 8.2.0, JDK 1.8, IntellJ IDEA 2016.1
There should be # as following in image URL. Put image file in inside project folder either same package or different package.
<Image url="#../image/profile_pic.png" />
Just try to refresh Eclipse's System Explorer. I solved it this way.
Path From Content Root
src/main/resources/assets/POMME.png =
<Image url="#../../../assets/POMME.png" />
This is because you haven't added jfoenix jar in your program.
Add jfoenix jar to your project
[xdezo.com][1]

JavaFX usage of "in jar" images in css

I am trying to add background image to some pane in my javafx application, the image is located inside the package resources.img and the css is located inside the package resources.css
if i setting the background image programmatically like suggested in this thread:
Setting background image by javafx code (not css)
it works fine but i would like to know if i can set the background image from the css file itself.
i tried
-fx-background-image: url("#../img/myImage.png");
but then the css interpreter didn't find the image file.
is it possible to do what i want via css?
JavaFX CSS parser has a limitation like
#-keyword statements are ignored.
described in "Limitations" section of CSS Reference Guide. It may be the cause of your problem though didn't confirm myself. Can you try like this: -fx-background-image: url("../img/myImage.png");
or -fx-background-image: url("resources/img/myImage.png");.
Perhaps someone it will be useful.
If you specified: -fx-background-image: url("resources/img/myImage.png");.
It's possible that standalone .jar file will successfully load the image while IDE(like Eclipse) won't. It because IDE alters path and will search something like: C:/My_project/resources/css/resources/img/myImage.png.
It means root for specified path will folder with css file instead of .jar package

Categories

Resources