JList Background Images..Urgent



Share on Google+Share on Google+

JList Background Images..Urgent
1 Answer(s)      6 years and 3 months ago
Posted in : Java Beginners

I has done a JList that can change background color when i selected each of it, but if i want to change background image rather than background colors, how can i do it?

Please help!

my previous coding as below: import java.awt.*; import javax.swing.*; import javax.swing.event.*;

public class ListTest extends JFrame{ private JList colorList; private Container container;

private final String colorNames[]={"Black","Blue","Cyan","Dark Gray","Gray","Green","Light Gray","Magenta","Orange","Pink","Red","White","Yellow"};

private final Color colors[]={Color.BLACK,Color.BLUE,Color.CYAN,Color.DARK_GRAY,Color.GRAY,Color.GREEN,Color.LIGHT_GRAY,Color.MAGENTA,Color.ORANGE,Color.PINK,Color.RED,Color.WHITE,Color.YELLOW

public ListTest()
    super("List Test");

    container.setLayout(new FlowLayout());

    colorList= new JList(colorNames);


    container.add(new JScrollPane(colorList));
        new ListSelectionListener(){

            public void valueChanged(ListSelectionEvent event){

public static void main(String args[])
    ListTest application=new ListTest();


View Answers

February 9, 2011 at 4:25 PM

Java JList select Background Image

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

public class BackgroundImage1{
private BufferedImage image;
private JPanel panel = new JPanel(){
protected void paintComponent(Graphics g){
if(image != null){
g.drawImage(image, 0, 0, this);
public BackgroundImage1(){
String files[]={"c:\\flower1.jpg","c:\\flower2.jpg","c:\\flower3.jpg","c:\\flower4.jpg"};
final JList list=new JList(files);
list.addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent e) {
        if (!e.getValueIsAdjusting()) {
String st = (String) list.getSelectedValue();
File file=new File(st);
image = ImageIO.read(file);
Dimension imageSize = new Dimension(image.getWidth(), image.getHeight());
catch(Exception ex){}

public JPanel getPanel(){
return panel;
public static void main(String[] args){
JFrame frame = new JFrame("BackgroundImage ");
frame.getContentPane().add(new BackgroundImage1().getPanel());


Related Tutorials/Questions & Answers:
JList Background Images..Urgent
JList Background Images..Urgent  I has done a JList that can change background color when i selected each of it, but if i want to change background image rather than background colors, how can i do it? Please help! my previous
jList  how to remove value from jlist after clicking on that value
JcomboBox to a Jlist  How to transfer a data from a JcomboBox to a Jlist ? Each time I select 1 item from a JComboBox, it will display in a JList
JList  pls tell me about the concept the JList in corejava? and tell me a suitable example
jList  how to add checkbox for every value in jlist having values populated from ms access database using java netbeans
jList  how to get the jlist values into jtextfield after clicking... value from the jlist to textfield. import java.awt.*; import javax.swing.*; import... JPanel implements ListSelectionListener { JList list; DefaultListModel listModel
jlist in swings
jlist in swings  how to populate jlist with all the data retrieved from the ms access database?plzz help
background  how to add image as background to a frame
Jlist and JTextfield
Jlist and JTextfield  How can we filter values from jlist by adding only a single letter in jtextfield such that when letter S is pressed in jtextfield then jlist should diplay all the values starting from letter S.I am using
Jtree connection with Jlist
Jtree connection with Jlist  I have a Jtree which contain different folders having files but the jtree will show only the folders. Now I want when I click a folder then its contained file will be shown in jList .How
Jtree connection with Jlist
Jtree connection with Jlist  I have a Jtree which contain different folders having files but the jtree will show only the folders. Now I want when I click a folder then its contained file will be shown in jList .How
jlist - Java Beginners
jlist  How to clear the display data from the jlist. Please help me... extends JPanel implements ListSelectionListener { JList list; DefaultListModel... = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE
JList - Swing AWT
JList  May i know how to add single items to JList. What...(); // model for = the JList JList list =3D new JList(listModel); you can... ListSelectionListener { private JList list; private DefaultListModel listModel
JList box java
JList box java We are going to describe JList box java. First of all we have created JList component of Swing. List is a component of GUI() Graphical User... you can select more than one item at once from the list. Example of JList
background image
background image  how to set background image in jsp using netbeans IDE 6.9
JList in java swings - Java Beginners
very urgent i tried out the following... JList controlButtons = new JList...JList in java swings  HI I am trying to create a JList of buttons... { private JList list; private DefaultListModel lm; private static
Create a JList Component in Java
Create a JList Component in Java       In this section, you will learn how to create a JList component of swing. JList is a component of GUI. It provides the multiple items
GRADIENT BACKGROUND  How to set gradient colors a s background for a jframe? pls help me..............   http://www.roseindia.net/java/example/java/swing/GradientColor.shtml
How to design a background, design a background, a background
How to design a background       If you don't have background, don't worry because you will learn here how to design a background by this example. New File: Take a new file. Choose
How to change background, change background
How to change background       This example will teach you to change background of any object... a picture to change background. Selection: Make selection by the Magic wand tool
HTML background images
HTML background images  How can I specify background images
picture in background in a HTML
picture in background in a HTML  How is picture displayed in background in a HTML
UIToolBar background image
UIToolBar background image  Hi, How to set background image of UIToolBar? Give me code for adding UIToolBar's background image. Thanks
div background color in html
div background color in html   How to change the background color of DIV in HTML
uiscrollview background color
uiscrollview background color  Is it possible to set the uiscrollview background color in iPhone application
UIButton background image
UIButton background image  Hi, How to create uibutton with background image? Thanks
HTML document's background color
HTML document's background color  How to set a HTML document's background color
background images in css not working
background images in css not working  In the application i'm passing a background image from CSS in the given format ... background-image: url... of adding background images in css
UITableView Background Image
UITableView Background Image  How to set an image as a background of UITableView in iPhone SDK   I think, we can't
Setting Tool Tip Text for items in a JList Component
Setting Tool Tip Text for items in a JList Component... the tool tip text for items present in the JList component of the Java Swing... and yellow background stay there for few seconds. This text show the information about
UITextfield Background Color
UITextfield Background Color  In my iPhone application, i am using... is ..it's showing a background color. Though my text field color is white. Can you please suggest.. , how can i remove the background color of text field. Thanks!  
Java Spring Hibernate Struts Training ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java


Advertisement null