Regarding Image in Swings

Regarding Image in Swings

Hi, I have some requireemnt like when i click on the button in frame,it wil display the image.....plz do the needful.............

View Answers

November 28, 2011 at 4:33 PM

import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class DisplayImage  {
JFrame f;
JButton browse;
JLabel label;
File file = null;
public DisplayImage() {
 f = new JFrame("");
 browse = new JButton("Display");
 label=new JLabel();

browse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(new ImageFileFilter());
int returnVal = chooser.showOpenDialog(null);

if(returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
String path=file.getPath();
ImageIcon myIcon = new ImageIcon(path);
label.setIcon(myIcon);
f.repaint();
}
}
});
f.setLayout(null);
browse.setBounds(10,20,100,20);
label.setBounds(10,40,350,300);
f.add(browse);
f.add(label);
f.setSize(350, 320);
f.setVisible(true);
}


public static void main(String[] args) {
new DisplayImage();
}

}
class ImageFileFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File file) {
if (file.isDirectory()) return false;
String name = file.getName().toLowerCase();
return (name.endsWith(".jpg") || name.endsWith(".png")|| name.endsWith(".gif"));
}
public String getDescription() { return "Images (*.gif,*.bmp, *.jpg, *.png )"; }
}









Related Tutorials/Questions & Answers:
Regarding Image in Swings
Regarding Image in Swings  Hi, I have some requireemnt like when i click on the button in frame,it wil display the image.....plz do the needful.............   import java.awt.*; import java.io.*; import javax.swing.
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
Advertisements
SWINGS
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
want help regarding a project
want help regarding a project  hiii this is hemangi and I want guidance that I am working on a project of hospital management system so I want guidance that how can i implement that in swings or with other frame work? and any
JSP & Swings
JSP & Swings  How to integrate jsp and swings
swings question
swings question  how to change the background color with the help of color values by using swings
swings for webnms
swings for webnms  if i am expanding node of jtree then i want to collapse previous expanding node of jtree in swings how is it possible
regarding rev
regarding rev  write a prog. in java that display all the arguments passed at the command line in reverse order
Regarding repository
Regarding repository  How to check in and check out using SVN repository using eclipse
Regarding tiles - Struts
Regarding tiles  I am taken image from Database.So, i am already... the session, its also shown. And I am also created one tiles for calling that image in the JSP, and insert the tiles in the respective papes, In which I want
Regarding 2 windows
Regarding 2 windows  Hi, I want 2 separate windows,when i click on a 1st window submit btn then it will show 2nd window. In 2nd window i want 1... in swings. Thanks in advance
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
Regarding Hibernate
Regarding Hibernate  Both JDBC and Hibernate are used to connect to database then whats the need of going to hibernate? What are the main differences? And could you let me know please
Regarding Project
Regarding Project  sir, i am doing a project in java. my project is CITY GUIDE it is an web application. please give me documentation of my project
Regarding Project
Regarding Project  sir, i am doing a project in java. my project is CITY GUIDE it is an web application. please give me documentation of my project
Doubts regarding images
Doubts regarding images  hello, I am dynamically generating an image in my system with out using database.. And i want the same image if i access the address bar url in other system image xhould be occur in other system
regarding images in jsp
regarding images in jsp  Hi, When I am trying to display an image in jsp, i am getting the image of bar charts in webroots/jspchart/web/jspbarchart.jsp.. But actually I am not getting any image in the browser.. Can any one help
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Regarding javascript
Regarding javascript  Hi, I want 4 upload buttons in HTML CODE and Among 4 browse buttons user is not selected any one then provide a prompt message like plz select any 1 file among 4 buttons.If user is selected either 1st
Swings & JSP
Swings & JSP  Hai all, Can we use Swing components in a JSP?? Suppose if we enter details in a swing dialog box..and If we want the result in a JSP..is that possible??? Thank you
image
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
swings - JDBC
swings  can a wavelet picturization to the image can be to retrieve a image from the database. please help me
Regarding Datasource
Regarding Datasource  Hi friend, Good morning,how r u,i want to share 1 information to u,I got a job in VERIZON DATA SERVICES INDIA PVT.LTD,u help a lot when i am in academic project,with that project only i got a job
regarding jtable...
regarding jtable...  sir, im working with jtables. i wanted to populate a jtable from the database and when i click any row it should add a container below that row itself and show the required details of the row
Java Swings
Java Swings  I am doing one project on java Swings, in this i have created one jframe where i defined some JButtons and Jcombobox's, here i need to insert one JTable with headers(IN CURRENT JFrame only).pls help me urgently
regarding project
regarding project  OBJECTIVES OF THIS PROJECT: -Ability to test the programmer for basic interaction skills to understand the client requirement. -Ability of the programmer to ask the right questions and get the relevant
regarding project
regarding project  OBJECTIVES OF THIS PROJECT: -Ability to test the programmer for basic interaction skills to understand the client requirement. -Ability of the programmer to ask the right questions and get
regarding project
regarding project   sir we need help about project. we have idea about his project please guide me sir. OBJECTIVES OF THIS PROJECT: -Ability to test the programmer for basic interaction skills to understand the client
swings header
swings header   have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains text "change request " like this. and the string3 should contain "123456 +(second string)+ hello" "second string can
Query regarding JSP, JDBC
Query regarding JSP, JDBC  can I get the code for the question asked by me regarding JSP,JDBC
swings
","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; for(i = 0
swings
swings
swings
swings
swings
swings
java swings
the background image using jframe and also set the jtext field and jlable boxes under the bachground image. Please send the code immediately,its very urgent.Please send me... image; private JPanel panel = new JPanel(new GridLayout(4,2)) { protected void
Swings and JDBC
Swings and JDBC  Hi.. I am vinay.. I am developing a small application using swings and mysql. I am sending part of the code here.. The problem is i need to update the mysql fields with values which are gettin from dynamiclly
regarding jdbc - JDBC
regarding jdbc  how i can configure java with ms access
Swings - Applet
Swings  Sir, I have developed an application in swings i want to call that class in applet. is it possible. or otherwise is there any way to deploy java class in browser. Give an example... Thanks in advance...  Hi
java swings - Java Beginners
java swings   Do you want to add textfields on the JPanel
how to create frame in swings
how to create frame in swings  how to create frame in swings
Regarding project - Applet
Regarding project  hi friend , iam doing project in Visual cryptography in Java so i need the Help regarding how to make a share of a original imahe into shares anu
Regarding weblogic portal
Regarding weblogic portal  Hi, My name is Ramanuja.i am working on weblogic portal.if u know any info regarding plz provide the materials or information to me.plz help me. Thanks in advance
regarding JTable - JDBC
regarding JTable  how to populate a JTable with mysql data after clicking JButton please explain with the example
regarding tags - Struts
regarding tags  What is the difference between html:submit and nested:submit and usage of tags based on the situation

Ads