Home Answers Viewqa Swing-AWT Regarding Image in Swings

 
 


k murali
Regarding Image in Swings
1 Answer(s)      a year and 6 months ago
Posted in : Swing AWT

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 Pages:
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
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
swings - JDBC
swings  can a wavelet picturization to the image can be to retrieve a image from the database. please help me
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
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 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
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
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
SWINGS  WHAT ARE THE DIFFERENCES BETWEEN AWT AND SWINGS
swings - Swing AWT
swings  i want to retrieve image using histogram of that image and display the histogram in the screen that is my problem
swings - Java Beginners
swings  how to get a buffered image from image   Hi Friend, Following method converts the image to buffered image: public static BufferedImage toBufferedImage(Image image) { if (image instanceof
swings - Java Beginners
swings  i want to fill a polygon with a image pattern,how can i do this , is there any inbuilt image pattern available in java
swings - Java Beginners
swings  how to add an image to combobox? i searched for this in google, but i got very difficult programs. i am beginner in java swings . i want a small example to add a image .gif file to combobox list. thank you   Hi
swings - Java Beginners
swings   how t upload images in swings. thanks   ...(null,"image is successfully uploaded and inserted."); } catch...()); Toolkit toolkit = Toolkit.getDefaultToolkit(); Image icon
swings - Java Beginners
swings  i created one jframe, in that i added ok button. i want to add some images with name in that frame .By selecting the image and press ok button it will display on the jpannel, how can i do
swings - Java Beginners
swings  I know how to add an image in a Panel with Netbeans but I... image; private JPanel panel = new JPanel() { protected void paintComponent(Graphics g){ super.paintComponent(g); if (image != null
java swings - Java Beginners
java swings   Hi , I have two listboxes.I want to move one listbox value into another listbox using add button. I have the code....Please check...); Image icon = Toolkit.getDefaultToolkit().getImage("e:\\zylog_logo.gif
java swings - Java Beginners
java swings   hi, I posted the same question two times,but i didnt get the reply. Please change the jframe look and feel type of code.please send...(200, 200); frame.setVisible(true); Image icon
awt swings - Swing AWT
awt swings  hello sir, My requirement is to insert captured image......  Hi friend, This code will be captured your image. Please...(); BufferedImage image = robot.createScreenCapture(new Rectangle
Swings - Java Beginners
Swings  Hi Friend... I have doubt on Swing concept.. How to display image... Which is d Right Statement to display Image... u plz send me d Statement that will display image... Thanks G.Sakthi
swings - Java Beginners
.In that window i want to add images, by selecting the image it will display... = st.executeUpdate(); JOptionPane.showMessageDialog(null,"image is successfully... = Toolkit.getDefaultToolkit(); Image icon = toolkit.getImage(f.getPath
swings - Java Beginners
swings  I want to add images(.jpeg,.gif) to a combobox list items.How can i acheive this..... Just now i send the above question.I got the below code fro you.I just change the image addresses in the Img[] string
swings - Java Beginners
swings   I want to add images(.jpeg,.gif) to a combobox list items.How can i acheive this..... Just now i send the above question.I got the below code fro you.I just change the image addresses in the Img[] string
Java swings - Swing AWT
Java swings  i have the following class .In that class i has two panels,panel1and panel2.panel1 contains an image.i want drag it in panel2(gray background).but i dont want to remove the image from panel1.i want
java swings - Java Beginners
java swings  Hi, This is my code. How can i set the image in the top of the page.Near by title label. Please send the code very urgent...); frame.setSize(200, 200); frame.setVisible(true); Image icon
java swings - Java Beginners
); frame.setVisible(true); Image icon = Toolkit.getDefaultToolkit
java swings - Java Beginners
); Image icon = Toolkit.getDefaultToolkit().getImage("e:\\zylog_logo.gif
java swings - Java Beginners
); frame.setVisible(true); Image icon = Toolkit.getDefaultToolkit().getImage("e
java swings - Java Beginners
); frame.setVisible(true); Image icon = Toolkit.getDefaultToolkit().getImage("e
Swings - Java Beginners
Swings  iam not getting the result.please help to me.code is below how to upload image. import java.sql.*; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import
java swings - Java Beginners
); frame.setVisible(true); Image icon = Toolkit.getDefaultToolkit().getImage
insert image using hibernate
insert image using hibernate  Sir, Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me
hibernate image Upload
hibernate image Upload  Sir, I had posted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me. Thanks
hibernate insert image
hibernate insert image  Sir, Today I hadposted question regarding upload image, th answer you had given is using SQL, but I am using Hibernate to insert data in the same table where I want to insert image. Plz hlp me. Thanks
File format validation and text field validation in java swings
File format validation and text field validation in java swings   i am reading a jpg image file throuh jfilechooser in java swings,when we press... 'please select jpg file only' plz give me the code in swings. Please
JSP & Swings
JSP & Swings  How to integrate jsp and swings
regarding rev
regarding rev  write a prog. in java that display all the arguments passed at the command line in reverse order
swings question
swings question  how to change the background color with the help of color values by using swings
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
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