Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  




Share on Google+Share on Google+

0 Answer(s)      7 years ago
Posted in : Java Beginners

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 and the remaining code is same has u given.
While i am trying to execute this code the following exception is raised.

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(
at comboboximage.Combo.createImageIcon(
at comboboximage.Combo.<init>(
at comboboximage.ImageInComboBox.main(
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)

help me...........

Hi Friend,

Try the following code:

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

class Combo extends JPanel {

String img[] = {"C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Sunset.jpg","C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Water lilies.jpg","C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/Winter.jpg"};
public Combo() {

JComboBox combo = new JComboBox();
ImageIcon[] images;

images = new ImageIcon[3];
Integer[] intArray = new Integer[3];
for (int i = 0; i < 3; i++) {
intArray[i] = new Integer(i);
images[i] = createImageIcon(img[i]);

setPreferredSize(new Dimension(200, 130));

protected static ImageIcon createImageIcon(String path) { imgURL = Combo.class.getResource(path);
return new ImageIcon(imgURL);

public class ImageInComboBox {

public static void main(String args[]){

JFrame frame = new JFrame("JCombobox Demo");

frame.add(new Combo());

More Questions
Post Answers

Ask Question Facing Programming Problem?

* Ask Questions?
* Browse Latest Questions
* Question-Answer Guidelines

View Answers

Related Tutorials/Questions & Answers:
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
Swings JTable
Swings JTable  add values to JTable with four coloums,two of them are comboboxes
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 that possible??? Thank you
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
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
","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; for(i = 0
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
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
Image Movement using Swings
Image Movement using Swings  How to move image using Swings
how to create frame in swings
how to create frame in swings  how to create frame in swings
Swings/awt - Swing AWT
Swings/awt  Hi, how to write action listeners to the Buttons in RichTextEditor tool bar.. thanks in's Urgent... i am very much new to Swings
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
java swings - Java Beginners
java swings   Hi, I need the code for click the refresh button then list values will be refresh.Please send the code ........... Thanks, Valarmathi
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
about swings - Java Beginners
about swings   Dear sir,Good evening, i am doing mca sir,i am doing the project in swings,so plz provide the material about swings sir Thank you  Hi Friend, Please visit the following link
java swings - Java Beginners
java swings   Hi, I need the code for joptionpane with jcombobox. my requirement is click on add button,one joptionpane will come.from the option pane i need to select the combobox values. Please send the sample code
java swings - Swing AWT
java swings  I am doing a project for my company. I need a to show the performance of the employees by using bar bharts. Please give me how can we write the code for bar charts using java swings.  Hi friend, I am
swings window header
swings window header  i have a string1 it contains 3 parts,for example "123456 service hello" and string2 contains "change request " like this. and the string3 should contain "123456 "........." hello" ".........." can
making of dynamic textfields using swings
making of dynamic textfields using swings  How to make dynamic textfields using java swings
another frame by using awt or swings
another frame by using awt or swings  how to connect one frame to another frame by using awt or swings
how can we store the encrypted passwaord in swings?
how can we store the encrypted passwaord in swings?   how can we store the encrypted passwaord in swings