Java Eclipse GUI Tutorial 7 # Add image, pictures and icons in JFrame
Вставка
- Опубліковано 19 вер 2024
- ★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqc...
Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
Kotlin Android Development Masterclass - bit.ly/2GcblsI
Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
★★★ Follow ★★★
My Website - www.codebind.com
DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
Donate to ProgrammingKnowledge -- (www.paypal.com...)
JFrame Add Background Image .... Java NetBeans
How to set background with an image
Insert an image in a Java GUI using Netbeans ...
How to set a background image in Netbeans -
Handling Images in a Java GUI Application - NetBeans
How to insert image into jFrame
java - Trouble Adding Background Image to JFrame in Netbeans
java - how to put Image on JPanel using Netbeans
Netbeans IDE Users - Add images to gui
adding background image to JFrame
Setting an icon for a jFrame in Netbeans swing gui builder
Displaying an Image on JPanel in NetBeans
How to set an image as background using Java on Netbeans
Java code to change the icon image on a jFrame?
Set Image As JFrame Background - Java
How to Load Images in Java Using NetBeans
add image and button to Jframe
Netbeans Tutorials Adding an Image
iit Learn java netbeans
java tutorial netbeans
Great video, one suggestion which will improve productivity. When selecting folder choose Package not Source folder. This then makes available in design view/Image Chooser, top selection button, Classpath Resources. Select this folder in parameters and images plus preview will show. Choose image and press OK. Source data will be automatically updated and only 1 (one) line of text data entered. No user interaction required.
MANN THANK YOU SO MUCHHH!!!
FF >> to 4:31 if you already have a grasp on the graphics/copyrights, etc.
Thanks for this!
There sure are critics against the style of the video, but in the end he knew something I didn't and helped me out with my problem. thank you sir
If you want to resize the image, you have to create a new instance of the image. By using this code:
Image newImage = img.getScaledInstance(90, 154, Image.SCALE_DEFAULT);
newImage is just the name of the new image, the "img." is the name of the previous image, and in the parenthesis (90,154) is the new size of the image.
thank you
use these packages:-
import javax.swing.Icon;
import javax.swing.ImageIcon;
this are imports and no packages xD
I love you so much. Indian Developer are the best. Love those tutorials!!!
4 and a half minutes he's showing how to download an image
i notice 6:43mins lol
You can get any image you want and use an autosize site to make it fit.
Thanks for this helpful tutorial series! Love from Bangladesh!
Hello Sir,
First of all EXCELLENT tutorial, really helped me out. Sir I was on my major project and was thinking to add image that act as login button instead of using JButton or any idea that an image can be used in login process. Could you please help me out with it.
Thank you! Been through all kind of forums, not one explained as well.
Exactly what I need! Thanks!!! Too clear :)
The imagem still didnt work.
I put like this
Image img = new ImageIcon(this.getClass().getResource("/login.png")).getImage();
label.setIcon(new ImageIcon(img));
and the image didnt show in the design and the aplication give me always a error of nullpointer right where i declared he image.
And i had to choose another name delare the image of the button.
Some ideia what should i do?
Th folder img must be a source folder
Thanks so much! You explained this so well, way better than any other place I've been to :)
+DiamondHoe11 label.setIcon(new ImageIcon(img)); it shows me a error
Just use a ImageIcon, don't use a label, it's a lot less versatile.
After all this hours....thank you...
is there a way where you can add an image to the background so it shows all the text and buttons an stuff?
nvm
i had to change the layer to abosolute my bad
you just need to arrange the layer
Code to resize image if it does not fit :
int y = addImage.getHeight(new ImageObserver() {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
// TODO Auto-generated method stub
return false;
}
});
int x = addImage.getWidth(new ImageObserver() {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
// TODO Auto-generated method stub
return false;
}
});
img = img.getScaledInstance(x,y, Image.SCALE_FAST);
for me Image img = new ImageIcon(this.getClass().getResource("/login.png")); didn't worked and throw errors. After Eclipse suggestion I have chabged it to ImageIcon img = new ImageIcon(this.getClass().getResource("/login.png")); nad everything ok
Add packge
import javax.swing.ImageIcon;
Daynewss This is simply because you forgot to add .getImage() at the end of that line.
Awesome video! keep up the good work :)
Tysm for making this video
Showing error when writing:
this.getClass
(cannot use in static context)
I am writing code in main method?
What wil be the solution?
Thank you so much! Super useful!
I am getting a error with the "this" keyword, cannot use this in static context, how do I fix this?
why can i resize when i place Jlabel but i can see it is resizable
THANK YOU!!!!!!
Very helpful, Thanks
This is easy to follow. Thank you ^_^
I've had a little mistake in the very end of this tutorial. I've wrote this:
Image img=new ImageIcon(this.getClass().getResource("/ok.png")).getImage();
button_Login.setIcon(new ImageIcon(img));
and the compiler gave me an error message:
"Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Duplicate local variable img"
The right thing to do was to write something different that just "img". Like "img1"
That have solved the problem.
+Alexander Khudyakov "Duplicate local variable img" Simply looking at the compilation error would have told you this immediately. If it says duplicate local variable, that means you have two variables called img. You can't have that because if I want to compare x with something (example if (x > 2)) and there are two values for x, how can I possibly test this statement?
Good job on finding it yourself though!
+Alexander Khudyakov same
It's hard to add anything. For some reason my screen blanked out. New standards require new programming, to wit:
ImageIcon icon = new ImageIcon ("Images/ET.png");
JLabel lblNewLabel = new JLabel("");
lblNewLabel.setIcon(icon);
lblNewLabel.setBounds(43, 19, 318, 225);
frame.getContentPane().add(lblNewLabel);
and at the top I just imported javax.swing.*
more out of frustration than for any real need, I guess. My images are in "Images" so that is different too.
how to add multiple image in jframe
how to enlarge the label with the JFrame when JFrame is maximunsize ??
I have a big image, but with this code, i can't make the image fit with the label. My label is smaller than the image.
How can I make the image fit with size of the label ?????????
+Chung Tú Đoàn Change the label.setBounds parameters. It should work.
For me, label doesn't have the setIcon() method. Does anyone know a workaround? Or am I possible doing something wrong?
what if you want to use 4 gif images?
May I ask that is it compulsory to import images to eclipse in order to use it in gui?
+Sy Lim Yes
you have to change also img variable name, otherwise you can't run your program 'cause of "Duplicate local variable img" error
wrote the code word for word why does it highlight ImageIcon and say it cannot be resolved to a type
hay there i need to kmow how to take a print of jFrame in eclips using a JButton
how do i add a video?
I am getting an error saying png cannot be resolved or is not a field
the word "get.Contentpane" is undefind for me ?
Is this video outdated? Granted, it's four years old. The reason I'm asking is because I can't find a Source Packages file in Netbeans.
The code for just copy paste:
import java.awt.Image;
import javax.swing.ImageIcon;
JLabel label = new JLabel ("");
Image img = new ImageIcon(this.getClass().getResource("/tank.jpg")).getImage();
label.setIcon(new ImageIcon(img));
label.setBounds(524, 96, 162, 240);
frame.getContentPane().add(label);
Insert an image in a Java GUI using Netbeans ....concept is good.can you upload .Java - Trouble Adding Background Image to JFrame in Netbeans
Works perfekt. Thank you very much.
can you make a same video for user login through a mySql database
Tried what I had just copied and found I had got it wrong when I tested it. This is what I got after I straightened out cut-and-paste errors:
JLabel lblNewLabel_2 = new JLabel("");
ImageIcon icon = new ImageIcon ("Images/ET.png");
lblNewLabel_2.setIcon(icon);
lblNewLabel_2.setBounds(417, 6, 337, 435);
frame.getContentPane().add(lblNewLabel_2);
Note that you have to be careful about fixing the label name that you actually used when you put the JLabel on your login screen. Also, be sure you used a "source folder" and not a regular photo for your images.
this is the right fix, thanks a lot mate
thank you
thank you!
can you tell me how to change icon of jframe in eclipse??
What if I Insert two images? How to do that?
Many had pix trouble. Not your fault. The way that works is:
ImageIcon icon = new ImageIcon ("img/ET.png");
JLabel lblNewLabel2 = new JLabel("");
lblNewLabel2.setIcon(icon);
lblNewLabel2.setBounds(25, 221, 300, 230); frame.getContentPane().add(lblNewLabel2);
There was a lblNewLabel above somewhere, so I had to distinguish the two.
how you get the design-view??
WindowBuilder
+Bitheral okay
how i can get this in netbeans ??
Video mt bom meu ajudou mt
Can we do it for netbeans
eclipse also runs under Ubuntu :p
Please send the code for resizing the image
I really need that
i found the problem.
I had to put frame.validate to handerize m imagens in the first run. =)
on writing the code in the video I'm getting this error
ImageIcon cannot be resolved to a type
Can someone please tell me how to resolve it?
SHIVAM GOYAL import java.awt.Image;
Import javax.swing.ImageIcon;
Sorry I was using the wrong login.png filename
what this software?
+Harut Odbash eclipse
Plz send the code for "how to upload image
63/5000
thank you very much. Link to download icon is not him
Thank you so much
But please can you send the code of how we can resize the uploaded image? Please it is urgent
Increase your speed of talking
Can you teach me how to resize an Image?
I really need that and cant find it anywhere
Your Android Studio-esque setup for eclipse is disgusting.
This guy just typed a keyword in a static context bruh
you can easily do it from just clicking icon button you waste my time
You'r beautiful!!!!!!!!!!!!!!
I FOUND A SCAMMER
Of course it have to be a indian teaching in this video.
*hello this is tech support*
lol HEHHEHAHHDHEDHHAHAHAHAHAHAHHA
XD
+GODZZ KING thats racist
xDDDDDDDDD
Well that's pretty racist, but I still laughed. XD
Racist? or Rapist? i always get comfused.
you're racist but you're not even good at basic grammar. Piece of shit
this is bad
Thanks!
Bro it does not work when I run it but I can see img is in my design site
+VIGNESH J.E Me, too!!!