473,385 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using JFileChooser to select only jpg, bmp, and gif files, then create ImageIcon

11
Basically, I have a GUI class where you have to use the JFileChooser class to select a jpg, bmp, or gif file. Then, that file is displayed on a jLabel as an Icon. The next step is taking that file chosen, turning it to grey scale, then displaying that as an Icon on another jLabel so that the user can see both of them at once.

I'm pretty sure I can do the turning to grey scale. My FileChooser is working in that I can choose a file from my computer, but I still haven't figured out how to use the filter to only allow jpg, bmp, and gif files, nor do I know how to use the file to display it as an Icon on the jLabels.

Any help would be appreciated. Thanks.

Koji
Oct 26 '06 #1
3 10703
r035198x
13,262 8TB
Basically, I have a GUI class where you have to use the JFileChooser class to select a jpg, bmp, or gif file. Then, that file is displayed on a jLabel as an Icon. The next step is taking that file chosen, turning it to grey scale, then displaying that as an Icon on another jLabel so that the user can see both of them at once.

I'm pretty sure I can do the turning to grey scale. My FileChooser is working in that I can choose a file from my computer, but I still haven't figured out how to use the filter to only allow jpg, bmp, and gif files, nor do I know how to use the file to display it as an Icon on the jLabels.

Any help would be appreciated. Thanks.

Koji
http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html#filters
Oct 26 '06 #2
Koji
11
Thanks, but I already figured out how to do the filters and Filechooser by the time I checked your post. That page for which you posted the URL was the page that was essential in figuring that out.

I never figured out how to save the file chosen and convert it to grayscale to create another icon of the grayscale, but I found a way to put a gray filter over the icon, which I'm hoping won't count off too much. Heh.
Oct 27 '06 #3
I'm pretty sure I can do the turning to grey scale. My FileChooser is working in that I can choose a file from my computer, but I still haven't figured out how to use the filter to only allow jpg, bmp, and gif files, nor do I know how to use the file to display it as an Icon on the jLabels.


This is very Simple process to select only jpg,bmp or gif files. What you need to do is just filter the files before you getting the values from JFileChooser.

Expand|Select|Wrap|Line Numbers
  1. JFileChooser chooser=new JFileChooser();
  2. FileNameExtensionFilter filter=new FileNameExtensionFilter("images", "jpg","gif","png");
  3.         fileChooser.setFileFilter(filter);
  4.         int returnVal=fileChooser.showOpenDialog(null);
  5.         File f=fileChooser.getSelectedFile();
  6.         if(returnVal==JFileChooser.APPROVE_OPTION)
  7.         {
  8. if(f.getName().endsWith(".jpg")||f.getName().endsWith(".gif"))
  9.             {
  10. JOptionPane.showMessageDialog(null,"Image file");
  11. }
  12. else
  13. JOptionPane.showMessageDialog(null,"select .jpg,.bmp or. gif");
Oct 18 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dado | last post by:
I create the jar with my classes, pictures and some txt files. The application is starting just fine if picture folder is out of the jar. If the folder picture is in the jar I don't see the...
5
by: crossroadsk | last post by:
I have implemented the following code : ----------------------------------------------------------------------------------------------------------------- import javax.swing.*; import java.awt.*; ...
1
by: Screenbert | last post by:
After finding nothing anywhere in google I am posting this so everyone can benefit by it. The formating is not pretty since I copied it from my word document, but you should benefit by it. ...
0
by: screenbert | last post by:
Managing DHCP Servers using C# They said it was impossible. It couldn't be done. But you can in fact manage DHCP servers using C#. This includes creating and deleting Scopes, SuperScopes,...
1
by: Apirsun | last post by:
I've been trying to use loops to add labels to a frame. I was able to get the program to compile but the labels aren't showing up. import javax.swing.*; import java.awt.*; import...
3
by: FinPingvin | last post by:
Hi! This code wont work properly, it returns true for showing all maps, but not any files. It is supposed to filter the JFileChooser to only show *.mp3 files. I have looked at it too long now, so...
1
crystal2005
by: crystal2005 | last post by:
Hi all, Can anyone tell me why my image doesn't appear in my frame's container? When I change imageIcon to just normal Label, it does go work. In another condition, if i don't use method...
2
by: Coreyja | last post by:
Im trying to display a png image by setting it as a ImageIcon and then putting that in a JLabel. I cant get it to display the image. I am using a null layout as it is the simplest way for me to get...
5
by: Scaran54 | last post by:
Hello, I am following a tutorial but have a problem. With the following code the icons will not appear unless I specify the entire path to where they are located, I cant work out why it wont work,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.