How to insert images using labels in NetBeans IDE, Java? - java

I'm making a virtual mall using NetBeans IDE 7.3.1
I inserted images using the following steps:
Drag and drop label onto frame
Go to label properties
Click on ellipsis of 'icon' option
Import to project, select desired image
Resize or reposition it accordingly.
Then, I saved the project, copied the project folder into a pendrive, tried to 'Open Project' in mate's laptop, using the same Java Netbeans IDE version.
When I tried to open the frames, they displayed empty labels, without images.
What went wrong?

Make sure that you have the image you want in the src folder of your project.
NetBeansProjects->YourProject->src->YourRequiredImage.
Now use the label properties and set icon from this folder.
Copy entire project folder to your friend's system and run. It should work.

Maybe the image was not imported properly.
Have you cross-verified that the image file was present in Netbeans Project Folder (maybe in the 'src' folder of your project or any other folder inside your project folder)?

Keep in mind always, If you want to give your app to someone else, So give your images too. And keep those images into the folder you have stored in.

Instead of using an external image, just create a resources folder in your src folder, and add the image to the folder. Then use select image from project. And select the folder from the drop-down and select the image.

That because your images are not included in the mentioned path ( path has been changed ). So always better to put your images in a Different PACKAGE under your project.

Related

How to create svg file in Eclipse

I'm making a web page with JSP and Eclipse Version: 2018-09 (4.9.0).
When working with VSCode, I simply create an empty svg file and paste the source code of image into it.
I expected Eclipse to behave as VSCode, however, it seems there is no svg file creating option for Eclipse.
Is an additional library essential to create svg file in Eclipse?
If not, I will be very much appreciated with your advice!
You can right-click on any folder or package in the file explorer or package explorer, or any file/class in the file explorer or package explorer, pick new, and then pick File. This will make a file in selected directory (/ directory that contains the source files of the selected package / same dir as the file/class you selected). Just enter the file name, and include the .svg file extension.
Eclipse will just treat it as a plain text file.
paste the source code of image into it.
If you mean, paste SVG in there - that works. If you mean: paste a PNG in there and expect the editor to create a bunch of scaffolding to have a PNG in an SVG, no that won't work, and that seems bizarre to want this, that is just getting you the worst aspects of PNG and the worst aspects of SVG.
I'm not aware of any SVG-specific plugins for eclipse.

JavaFX, can't get icon on the title bar to show up after exporting to *.JAR

Every time I export my project into *.jar in eclipse I lose all of images in my project (in Eclipse). I've tried to put images directly into the *.jar and it works in some other cases but not this one.
Fragment of code with loading of this icon:
primaryStage.getIcons().add(new Image("file:icon.png"));
You're loading the image from the working directory, not the jar itself. This is why it's working in development, and not in production. If you move the image to the same folder as the jar is located it should work, but I'm assuming you want the image to be contained inside your jar file.
Move the image to one of your packages (any, as long as it gets bundled with the jar). Then you need to access the image, use the ClassLoader.getResourceAsStream(String) for this. It looks like you're using javafx, so you can use this to get your image: primaryStage.getIcons().add(new Image(ClassLoader.getSystemResourceAsStream("the/path/to/your/image.png"));.
to work with the files inside the jar, need to use ZipInputStream or JarInputStream

splashscreeen not working in netbeans IDE for java?

slash screen tutorial
By following the above tutorial i did the following things
step1: created a new project named SplashScreenTest
step2: include the gif file named laoding.gif in the project
step3: added a new JFrameForm to project with the name StartGUI.java
step4: rightclick the form->properties->code->form size
policy->generate resize code
generate position ->untick
generate size ->untick
generate center ->tick
step5: replaces "Nimbus" with "Windows" inside
step6: right click SplashScreenTest->properties->VMoptions
-splash:src/AppPackage/loading.gif
step7 : open Manifest.mf write "SplashScreen-Image:
AppPackage/loading.gif"
step8: set main class to AppPackage.StartGUI
Now as soon as i hit the clean and build button it returns an error
"existing manifest file is invalid"
May I know what is the correct way to achieve my objective?Maybe this question too basic, but i did't find any suitable solution.Please Help me out.
I'm kind of weirded out by the hoops you are jumping through, Netbeans actually provides support for the splash-screen via the Project's Properties
Right click the project node...
Select the "Application" properties...
Browse for the splash screen image to be used...Netbeans will automatically included within the compiled jar file...
Clean and build your project...

How to change default java logo exe icon on the taskbar in javafx?

I made a JavaFX application on Netbeans and I put this code for setting the icon to the window
primaryStage.getIcons().add(new Image("file:sicadcam.png"));
and when I run the project from Netbeans, it works ok: the icon appears on the window and in the taskbar. where I have to put the image.
When I clean and build the project, it generates two installers: one exe and one msi; and when I install the application and open it, the window doesn't have the icon sicadcam.png, it has the default java logo icon.
How or where can I set the path of the image so that when I install the application the icon appears.
You should place the icon in your jar or classpath and then load it through a resource function.
E.g. if you place it to your bin folder, into the package where your class is, then the following should work:
primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("sicadcam.png")));
I suspect that the image is not handled as a resource and not getting into your Jar file. Can you verify if it is there? (You can do that by Total Commander for example by pressing Ctrl+PgDown to go into the archive).
Another reason might be that NetBeans using a different run configuration and classpath. Where is your image? If it is in the package root (i.e., the folder which contains your top-level package), you can probably access it somehow like: ImageIO.read(getClass().getResourceAsStream("/sicadcam.png")).
Hope that helps something.

Java application wont load images after exporting

I have problem with eclipse, after i export my application into jar or runnable jar file app doesnt load images.When i run application inside eclipse it runs fine all images loaded properly.I tryed to move my source folder inside default src folder which doesnt helped. Also tryed to import all images one more time,Refreshing project , changing code to getClass().getResource("imgs\someimage.png") , making a new folder and moving everything there,also copy/paste whole classes into another project.Wierd thing is that i have same style in another project and everything work just fine!Bud in this case i cant get it to work.Build path is set perfectly just like project before.And all the images that i need after exporting into jar i see inside it.I use example: labelIcon.setIcon(new ImageIcon("imgs\\someimage.png")); for most people getClass().getResource()... fixed the problem , bud in my case not. Any ideas??Might this be a bug in Eclipse?
Instead of creating imgs folder, create package instead (in src folder). I.e. org.imgs. And then load images as resources:
getClass().getResource("/org/imgs/nameOfImage.png")

Categories