Can ArrayList accept an ImageIcon >>????

Can ArrayList accept an ImageIcon >>????

haw can create ArrayList witch can accept Image ..mean when i use add() method, instead item let me add image to the ArrayList in run time .{should be the program using GUI}.. please help me please

View Answers

April 21, 2011 at 3:53 PM

import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;

public class ListOfImages{
public static void main(String[] args){
final JLabel lab=new JLabel();
final JFrame f=new JFrame();
f.setLayout(null);
ArrayList al=new ArrayList();
Scanner input=new Scanner(System.in);
System.out.println("Enter Images names with path:");
for(int i=0;i<5;i++){
String image=input.nextLine();
al.add(image);
}
Object[] ol = al.toArray();
final JList list=new JList(ol);
list.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
if(!e.getValueIsAdjusting()){
String st = (String) list.getSelectedValue();
System.out.println(st);
ImageIcon icon=new ImageIcon(st);
lab.setIcon(icon);
f.repaint();     
}
   }
   });
  lab.setBounds(120,10,300,200);
list.setBounds(10,10,100,100);
f.add(list);

f.add(lab);
f.setVisible(true);
f.setSize(500,200);
 }
}

April 29, 2011 at 4:36 AM

think u dear friend ,,but when i determine path the image .how ?? must be write the name of image ?? can u take me an another example that how can i add an image to the arraylist ..? think u please help .. do think right this path { C:\Users\Didar\Desktop\image }..??









Related Tutorials/Questions & Answers:
Can ArrayList accept an ImageIcon >>????
can Stack accept imageIcon ..??
Advertisements
arraylist
arraylist
arraylist
arraylist of an arraylist
arraylist
ArrayList
arraylist
How Can I get ArrayList of Data from jsp with ajax request
ModuleNotFoundError: No module named 'accept'
ArrayList programe
ArrayList as an argument to another class
Java arraylist of arraylist
ModuleNotFoundError: No module named 'paymob_accept'
ModuleNotFoundError: No module named 'paymob_accept'
ModuleNotFoundError: No module named 'accept-types'
ModuleNotFoundError: No module named 'flask_accept'
Accept Language and Accept Char set in Servlets
comparing arraylist of an multi dimensional arraylist
arraylist and vector
Java ArrayList
ArrayList in java
ArrayList and Vector
arraylist in java
array accept all data type
array accept all data type
accept integer from user
How to sort ArrayList in java
ModuleNotFoundError: No module named 'django-accept-header'
ModuleNotFoundError: No module named 'mastercard-mpqr-accept'
ModuleNotFoundError: No module named 'parse-accept-language'
ModuleNotFoundError: No module named 'accept-header-match'
ModuleNotFoundError: No module named 'django-accept-header'
ArrayList object
Remove multiple elements in arraylist
Java arraylist to array
Accept command in Oracle
button to accept user input
ArrayList elements
How to Convert ArrayList to Array?
Java ArrayList Example
accessor arrayList
To render imageicon to image component - Java Server Faces Questions
arraylist with session - JSP-Servlet
Diff between ArrayList and Vector?
Cannot assign an ArrayList to an empty ArrayList
to use ArrayList in the place of Vector
to use ArrayList in the place of Vector
vector and arraylist

Ads