Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Answers Viewqa Java-Beginners about java swing

View Questions and Answers by Category


Have Programming Question? Ask it here!

sunil kumar pandey
about java swing
1 Answer(s)      5 years ago
Posted in : Java Beginners

How to upload the pictures and photo on the panel in java swing ,plz help
thank a lot.

View Answers

March 4, 2010 at 12:51 PM

Hi Friend,

Try the following code:

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

public class UploadImage extends JPanel {
static File file=null;
int index;
JButton button;
BufferedImage bi, bufferImage;
int w, h;

public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel panel = new UploadImage();
frame.setSize(300, 100);
public UploadImage(){
button=new JButton("Browse");
button.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();
bi =;
w = bi.getWidth(null);
h = bi.getHeight(null);
if (bi.getType() != BufferedImage.TYPE_INT_RGB) {
BufferedImage bi2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics big = bi2.getGraphics();
big.drawImage(bi, 0, 0, null);
bufferImage = bi = bi2;
catch(Exception ex){}
public Dimension getPreferredSize() {
return new Dimension(w, h);
public void paint(Graphics g) {
g.drawImage(bufferImage, 0, 0, null);
public void filterImage(){
BufferedImageOp op = null;
switch (index){
case 0:
bufferImage = bi;
case 1:
bufferImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
op.filter(bi, bufferImage);
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:
about swing - Java Beginners
about swing  how implement a program of adding two numbers by entering two numbers separately by other user on the input dialog box and after that also show the result of the addition in other dialog box... your regardly
about java swing - Java Beginners
about java swing   How to upload the pictures and photo on the panel in java swing ,plz help thank a lot.  Hi Friend, Try the following code: import java.awt.*; import*; import javax.swing.*; import
about java swing - Java Beginners
about java swing   How to send date in data base if i use the combobox like as dd,mm,yyyy. plz reply thanx a lot  Hi Friend, Try the following code: import java.sql.*; import java.awt.*; import javax.swing.
About jcombobox - Swing AWT
About jcombobox  Hi all, I am new to this forum. Can we do auto suggest jcombobox in swing? If yes is there any jar file for that or any code if you have. Thanks in advance.   Hi Friend, Try the following code
Swing In Java
Swing In Java In this tutorial we will read about the various aspects of Swing.... This example will demonstrate you about how to use the Swing components in Java... technologies. Later, the JFC was renamed to Swing. Before, the Java version 1.2
java swing - Swing AWT
java swing  how i can insert multiple cive me exampleolumn and row in one JList in swing?plz g  Hi Friend, Please clarify your question. Thanks
java swing
java swing  view the book details using swing
Java swing
Java swing  Does Swing contains any heavy weight component
Java swing
Java swing  what are the root classes of all classes in swing
java swing
java swing  what is java swing   Swing is a principal GUI toolkit for the Java programming language. It is a part of the JFC (Java Foundation Classes), which is an API for providing a graphical user interface for Java
java swing
java swing  how to connect database with in grid view in java swing   Hi Friend, Please visit the following link: Grid view in java swing Thanks
Java swing
Java swing  Write a java swing program to calculate the age from given date of birth
java swing
java swing  add two integer variables and display the sum of them using java swing
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend, Try the following code: import java.awt.*; import java.awt.image....: Thanks
java swing - Swing AWT
java swing   how i can insert in JFrame in swing?  Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class FormDemo extends JFrame { JButton ADD; JPanel
java swing - Swing AWT
java swing   Iam developing a java web browser.Actually my code works fine ie. i can load a web page without proxy.But in my place i have only proxy... a proxy or how to make my java web browser to listen to proxy setting??? please help
JAVA SWING  Hi.... Iam doing project in java...and my front end in swing ..our project is like billing software... then what are the topics i want cover? then how to design? pls help me
java swing.
java swing.  Hi How SetBounds is used in java programs.The values in the setBounds refer to what? ie for example setBounds(30,30,30,30) and in that the four 30's refer to what
Java swing
to the database using java swing...Java swing  I create one table. That table contains task ID and Task Name. When I click the task ID one more table will be open and that table
Java swing
are displayed in the table..I need the source code in java swing...Java swing  If i am login to open my account the textfield,textarea and button are displayed. if i am entering the time of the textfield
java swing - Swing AWT
java swing  how to save data in sql 2005 while insert in textfield  Hi Friend, Try the following code: import java.sql.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; import
java - Swing AWT
What is Java Swing AWT  What is Java Swing AWT
swing - Java Beginners
Swing application testing  What are the conventions for testing a Java swing application
Java swing
Java swing  how to create simple addition program using java swing?   import java.awt.*; import javax.swing.*; import java.awt.event.*; class SumOfNumbers extends JFrame { SumOfNumbers(){ JLabel lab1=new
Java swing
Java swing  when i enter the time into the textbox and activities into the textarea the datas saved into the database.the java swing code for the above item   import java.sql.*; import java.awt.*; import javax.swing.
java swing
java swing  what is code for diplay on java swing internal frame form MYSQL DB pls send   Here is a code of creating form on jinternalframe and connect to mysql. import*; import java.sql.*; import java.awt.
About Java
About Java  Hi, Can anyone tell me the About Java programming language? How a c programmer can learn Java development techniques? Thanks   Hi, Read about java at Thanks
Java swing
Java swing  How to combine two java files
java swing
java swing  meaning of out.flush
Java swing
Java swing  What method is used to specify a container's layout
What is Java Swing?
What is Java Swing?       Here, you will know about the Java swing. The Java Swing provides... and GUIs components. All Java Swing classes imports form the import