How To Display Image In Jlabel Java Using Netbeans GUI App

Опубликовано: 04 Октябрь 2024
на канале: Maurice Muteti
10,839
88

How To Display Image In Jlabel Java Using Netbeans GUI App
Source Code 1 - https://bit.ly/2IEphfr

In this video we are going to :
1. Select image from computer using java JFileChooser.
2. Display selected image on Jlabel As ImageIcon.
3. Resize selected image to fit on jlabel.
4. Filter only png, jpg, jpeg and gif Images.
5. Check If Open button has been clicked, So that we can get image file path.


Steps to follow :
Step 1. Start netbeans IDE.
Step 2. Create new Java project. Uncheck create main class when creating project or you can delete the main class after you create new project.
Step 3. Right Click on package name and select new, and click jframe form.
Step 4. Drag and drop button from the palette.
Step 5. Right Click On The button, Select edit to change button name.
Step 6. Create a J File Chooser object.
Step 7. J File Chooser enables user to choose files from a computer or save files.
Step 8. File Name Extension Filter enables you to filter name extension. So here we need only four image name extensions. (png, jpg, jpeg and gif).
Step 9. The First argument is a string description, and the following are the image extensions.
Step 10. Show open dialog - Pops up an "Open File" file chooser dialog.
Step 11. Now we are checking if open button has been clicked. If so, the code inside the if is executed.
Step 12. Here we're getting the selected file.
Step 13. Get the path of selected image and store it in a string.
Step 14. Display path on message dialogue.
Step 15. Drag and drop jlabel from the palette to jframe where image will be displayed.
Step 16. Now let's resize the image to make sure it fits on jlabel.
Step 17. The image fits and displays successfully on the jlabel.


Social Networks :
Twitter -   / ea_plus  
Pinterest -   / mauricemuteti20  
Instagram -   / mauricemuteti2015  
Facebook Profile- https://www.facebook.com/profile.php?...
Facebook page -   / tutorials-1774183349512667  
vk https://vk.com/id444057925
mix - https://mix.com/mauricemuteti
Linkedin   / learning-tutorials-731a29114  
Wordpress - https://mauricemutetingundi.wordpress...
Blogspot - http://mauricemutetingundi.blogspot.com/
Tumblr -   / mauricemuteti2015  
Channel -    / @mauricemutetingundi  
Github - https://github.com/mauricemuteti/
Flickr - https://www.flickr.com/people/1279000...