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
3 10703
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
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.
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. - JFileChooser chooser=new JFileChooser();
-
FileNameExtensionFilter filter=new FileNameExtensionFilter("images", "jpg","gif","png");
-
fileChooser.setFileFilter(filter);
-
int returnVal=fileChooser.showOpenDialog(null);
-
File f=fileChooser.getSelectedFile();
-
if(returnVal==JFileChooser.APPROVE_OPTION)
-
{
-
if(f.getName().endsWith(".jpg")||f.getName().endsWith(".gif"))
-
{
-
JOptionPane.showMessageDialog(null,"Image file");
-
}
-
else
-
JOptionPane.showMessageDialog(null,"select .jpg,.bmp or. gif");
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: crossroadsk |
last post by:
I have implemented the following code :
-----------------------------------------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
...
|
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.
...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
| | |