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

КОМЕНТАРІ • 114

  • @markrashleigh7018
    @markrashleigh7018 5 років тому +6

    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.

  • @neilguylindberg6672
    @neilguylindberg6672 8 років тому +8

    FF >> to 4:31 if you already have a grasp on the graphics/copyrights, etc.
    Thanks for this!

  • @perkelele
    @perkelele 4 роки тому +2

    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

  • @piro6820
    @piro6820 6 років тому +15

    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.

  • @AJAYKUMAR-vd5py
    @AJAYKUMAR-vd5py 6 років тому +13

    use these packages:-
    import javax.swing.Icon;
    import javax.swing.ImageIcon;

  • @mrpartyld4246
    @mrpartyld4246 3 роки тому +3

    I love you so much. Indian Developer are the best. Love those tutorials!!!

  • @nikolabl8154
    @nikolabl8154 6 років тому +65

    4 and a half minutes he's showing how to download an image

    • @xxxx-kv9ei
      @xxxx-kv9ei 5 років тому +2

      i notice 6:43mins lol

  • @hayian2575
    @hayian2575 4 роки тому +1

    You can get any image you want and use an autosize site to make it fit.

  • @smdedar
    @smdedar 6 років тому +2

    Thanks for this helpful tutorial series! Love from Bangladesh!

  • @aakashdeep7616
    @aakashdeep7616 7 років тому +1

    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.

  • @williamfilho1955
    @williamfilho1955 8 років тому

    Thank you! Been through all kind of forums, not one explained as well.

  • @jasonaraosfuentes2130
    @jasonaraosfuentes2130 8 років тому +1

    Exactly what I need! Thanks!!! Too clear :)

  • @ProgrammingKnowledge
    @ProgrammingKnowledge  10 років тому

  • @keziacp
    @keziacp 9 років тому +1

    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?

  • @truekip312
    @truekip312 8 років тому

    Thanks so much! You explained this so well, way better than any other place I've been to :)

    • @Creatorph
      @Creatorph 8 років тому

      +DiamondHoe11 label.setIcon(new ImageIcon(img)); it shows me a error

    • @truekip312
      @truekip312 8 років тому +1

      Just use a ImageIcon, don't use a label, it's a lot less versatile.

  • @fisiobackup2018
    @fisiobackup2018 4 роки тому

    After all this hours....thank you...

  • @blankbtw8675
    @blankbtw8675 8 років тому +3

    is there a way where you can add an image to the background so it shows all the text and buttons an stuff?

    • @blankbtw8675
      @blankbtw8675 8 років тому

      nvm
      i had to change the layer to abosolute my bad

    • @ralpdexter2495
      @ralpdexter2495 7 років тому

      you just need to arrange the layer

  • @rohit-gupta
    @rohit-gupta 7 років тому +1

    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);

  • @DainiusDainius
    @DainiusDainius 9 років тому +5

    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

    • @magicalkunal
      @magicalkunal 9 років тому +1

      Add packge
      import javax.swing.ImageIcon;

    • @kakaiablev
      @kakaiablev 9 років тому

      Daynewss This is simply because you forgot to add .getImage() at the end of that line.

  • @mackkek7603
    @mackkek7603 7 років тому

    Awesome video! keep up the good work :)

  • @thiralipatel1764
    @thiralipatel1764 5 років тому +1

    Tysm for making this video

  • @qazijawad6451
    @qazijawad6451 2 роки тому

    Showing error when writing:
    this.getClass
    (cannot use in static context)
    I am writing code in main method?
    What wil be the solution?

  • @Sebastian-dp5sp
    @Sebastian-dp5sp 7 років тому

    Thank you so much! Super useful!

  • @kameerhosein5748
    @kameerhosein5748 2 роки тому

    I am getting a error with the "this" keyword, cannot use this in static context, how do I fix this?

  • @imissyouj
    @imissyouj 3 роки тому

    why can i resize when i place Jlabel but i can see it is resizable

  • @domicmc
    @domicmc 9 років тому +2

    THANK YOU!!!!!!

  • @rashedahmed6339
    @rashedahmed6339 Рік тому

    Very helpful, Thanks

  • @rodolfogarcia3736
    @rodolfogarcia3736 6 років тому

    This is easy to follow. Thank you ^_^

  • @ОлександрХудяков-н2р
    @ОлександрХудяков-н2р 8 років тому +1

    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.

    • @PressStartLetsPlay
      @PressStartLetsPlay 8 років тому

      +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!

    • @Creatorph
      @Creatorph 8 років тому

      +Alexander Khudyakov same

  • @patrickemoran2220
    @patrickemoran2220 6 років тому

    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.

  • @pauljope5009
    @pauljope5009 7 років тому +2

    how to add multiple image in jframe

  • @HuyNguyen-cc5ih
    @HuyNguyen-cc5ih 9 років тому

    how to enlarge the label with the JFrame when JFrame is maximunsize ??

  • @tuoan5533
    @tuoan5533 8 років тому +1

    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 ?????????

    • @santiagol365
      @santiagol365 8 років тому

      +Chung Tú Đoàn Change the label.setBounds parameters. It should work.

  • @Thimo98
    @Thimo98 7 років тому

    For me, label doesn't have the setIcon() method. Does anyone know a workaround? Or am I possible doing something wrong?

  • @inmysoul_TLH
    @inmysoul_TLH 5 років тому

    what if you want to use 4 gif images?

  • @sy3233
    @sy3233 9 років тому

    May I ask that is it compulsory to import images to eclipse in order to use it in gui?

  • @slimakdrzewny
    @slimakdrzewny 9 років тому

    you have to change also img variable name, otherwise you can't run your program 'cause of "Duplicate local variable img" error

  • @sulliexxx2147
    @sulliexxx2147 7 років тому

    wrote the code word for word why does it highlight ImageIcon and say it cannot be resolved to a type

  • @sumitxx7
    @sumitxx7 8 років тому

    hay there i need to kmow how to take a print of jFrame in eclips using a JButton

  • @Agent47709
    @Agent47709 9 років тому +1

    how do i add a video?

  • @sandeepb8443
    @sandeepb8443 10 років тому

    I am getting an error saying png cannot be resolved or is not a field

  • @GoldChopper
    @GoldChopper 4 роки тому

    the word "get.Contentpane" is undefind for me ?

  • @itssashadw6371
    @itssashadw6371 5 років тому

    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.

  • @InsideMuseums
    @InsideMuseums Рік тому

    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);

  • @rameshpitla783
    @rameshpitla783 10 років тому

    Insert an image in a Java GUI using Netbeans ....concept is good.can you upload .Java - Trouble Adding Background Image to JFrame in Netbeans

  • @xile1337
    @xile1337 7 років тому

    Works perfekt. Thank you very much.

  • @engineerali7146
    @engineerali7146 10 років тому

    can you make a same video for user login through a mySql database

  • @patrickedwinmoran2966
    @patrickedwinmoran2966 6 років тому

    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.

    • @RohitAVS
      @RohitAVS 5 років тому

      this is the right fix, thanks a lot mate

  • @chaimaziad7404
    @chaimaziad7404 4 роки тому

    thank you

  • @Elena-hj3fb
    @Elena-hj3fb 7 років тому

    thank you!

  • @mylifeassaifi1708
    @mylifeassaifi1708 8 років тому

    can you tell me how to change icon of jframe in eclipse??

  • @johnybravo4054
    @johnybravo4054 5 років тому

    What if I Insert two images? How to do that?

  • @patrickedwinmoran2966
    @patrickedwinmoran2966 6 років тому

    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.

  • @jonasbernard
    @jonasbernard 8 років тому +1

    how you get the design-view??

  • @wawy0
    @wawy0 4 роки тому

    how i can get this in netbeans ??

  • @leonardoiglesias751
    @leonardoiglesias751 2 роки тому

    Video mt bom meu ajudou mt

  • @anshurajput5832
    @anshurajput5832 5 років тому

    Can we do it for netbeans

  • @Toumasu
    @Toumasu 9 років тому

    eclipse also runs under Ubuntu :p

  • @니산-b6i
    @니산-b6i 6 років тому

    Please send the code for resizing the image
    I really need that

  • @keziacp
    @keziacp 9 років тому

    i found the problem.
    I had to put frame.validate to handerize m imagens in the first run. =)

  • @shivamgoyal1487
    @shivamgoyal1487 7 років тому

    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?

    • @srikararanganath8012
      @srikararanganath8012 7 років тому

      SHIVAM GOYAL import java.awt.Image;
      Import javax.swing.ImageIcon;

  • @rowdyhopper
    @rowdyhopper 9 років тому

    Sorry I was using the wrong login.png filename

  • @odbashWizard
    @odbashWizard 8 років тому

    what this software?

    • @lemonsq
      @lemonsq 8 років тому

      +Harut Odbash eclipse

  • @abhishekjoshi9296
    @abhishekjoshi9296 6 років тому

    Plz send the code for "how to upload image

  • @duytien3979
    @duytien3979 6 років тому

    63/5000
    thank you very much. Link to download icon is not him

  • @alishibli4720
    @alishibli4720 7 років тому

    Thank you so much
    But please can you send the code of how we can resize the uploaded image? Please it is urgent

  • @shehjadishan8305
    @shehjadishan8305 5 років тому

    Increase your speed of talking

  • @yaron1m
    @yaron1m 9 років тому

    Can you teach me how to resize an Image?
    I really need that and cant find it anywhere

  • @joesmith3417
    @joesmith3417 8 років тому

    Your Android Studio-esque setup for eclipse is disgusting.

  • @gg_man3347
    @gg_man3347 2 роки тому

    This guy just typed a keyword in a static context bruh

  • @lahirunimnajith3519
    @lahirunimnajith3519 5 років тому

    you can easily do it from just clicking icon button you waste my time

  • @tomt8201
    @tomt8201 9 років тому

    You'r beautiful!!!!!!!!!!!!!!

  • @Festive_Fox07
    @Festive_Fox07 4 роки тому

    I FOUND A SCAMMER

  • @godzzking8829
    @godzzking8829 9 років тому +40

    Of course it have to be a indian teaching in this video.
    *hello this is tech support*
    lol HEHHEHAHHDHEDHHAHAHAHAHAHAHHA
    XD

    • @alexmoga8654
      @alexmoga8654 8 років тому +3

      +GODZZ KING thats racist

    • @nailmirror
      @nailmirror 7 років тому

      xDDDDDDDDD

    • @anilmawji
      @anilmawji 7 років тому

      Well that's pretty racist, but I still laughed. XD

    • @angeredquasar9029
      @angeredquasar9029 7 років тому +2

      Racist? or Rapist? i always get comfused.

    • @Kingslayer94
      @Kingslayer94 6 років тому +1

      you're racist but you're not even good at basic grammar. Piece of shit

  • @vladeb1104
    @vladeb1104 5 років тому

    this is bad

  • @xlyzplayer134
    @xlyzplayer134 8 років тому

    Thanks!

  • @vigneshj.e5422
    @vigneshj.e5422 9 років тому

    Bro it does not work when I run it but I can see img is in my design site