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 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=getContentPane();
container.setLayout(new FlowLayout());
colorList= new JList(colorNames);
colorList.setVisibleRowCount(5);
colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
container.add(new JScrollPane(colorList));
colorList.addListSelectionListener(
new ListSelectionListener(){
public void valueChanged(ListSelectionEvent event){
container.setBackground(
colors[colorList.getSelectedIndex()]);
}
}
);
setSize(350,150);
setVisible(true);
}
public static void main(String args[])
{
ListTest application=new ListTest();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
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){
super.paintComponent(g);
if(image != null){
g.drawImage(image, 0, 0, this);
}
}
};
public BackgroundImage1(){
panel.setLayout(null);
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();
System.out.println(st);
try{
File file=new File(st);
image = ImageIO.read(file);
Dimension imageSize = new Dimension(image.getWidth(), image.getHeight());
panel.setPreferredSize(imageSize);
panel.repaint();
}
catch(Exception ex){}
}
}
});
list.setBounds(100,10,100,100);
panel.add(list);
}
public JPanel getPanel(){
return panel;
}
public static void main(String[] args){
JFrame frame = new JFrame("BackgroundImage ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new BackgroundImage1().getPanel());
frame.setSize(300,150);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Related Tutorials/Questions & Answers:
JList Background Images..UrgentJList 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
jListjList how to remove value from
jlist after clicking on that value
Advertisements
JlistJcomboBox 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 JListJList pls tell me about the concept the
JList in corejava? and tell me a suitable example
jListjList how to add checkbox for every value in
jlist having values populated from ms access database using java netbeans
jListjList 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
backgroundbackground how to add image as
background to a frame
jlist in swingsjlist in swings how to populate
jlist with all the data retrieved from the ms access database?plzz help
Jlist and JTextfieldJlist 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 JlistJtree 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 JlistJtree 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 Beginnersjlist 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 AWTJList 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
background imagebackground image how to set
background image in jsp using netbeans IDE 6.9
JList box javaJList 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 GRADIENT BACKGROUNDGRADIENT 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
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
How to change background, change background
How to change
background
This example will teach you to change
background of any object... of the another picture to make
background
picture.
Paste: Go to Edit menu > Paste
UIToolBar background imageUIToolBar
background image Hi,
How to set
background image of UIToolBar? Give me code for adding UIToolBar's
background image.
Thanks
ModuleNotFoundError: No module named 'background'ModuleNotFoundError: No module named '
background' Hi,
My Python... '
background'
How to remove the ModuleNotFoundError: No module named '
background' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'background'ModuleNotFoundError: No module named '
background' Hi,
My Python... '
background'
How to remove the ModuleNotFoundError: No module named '
background' error?
Thanks
Hi,
In your python environment you
background images in css not workingbackground 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
Jbutton[] background & foregroundcolor changeJbutton[]
background & foregroundcolor change how to change... foreground and
background color is changed. the remaining jbutton foreground and
background color are not changed.
next i select button[9] then the button[5] foreground
UITextfield Background ColorUITextfield
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!
UIView Background ImageUIView
Background Image HI,
Please let's know how to add
background image to a view?
Thanks
Hi
You can use the following code...:@"myimage.png"]];
Read more at UIView Image
Background Tutorial page.
Thanks
div style backgrounddiv style background How to add
background color to a div? What is the code of div style
background?
Hi,
You can use the following code:
<div style="
background-color: #ccffcc;">
<p>Content</p>
<
how to set background imagehow to set
background image how to set image in
background in that image i want over lay text how it possible in jsp?
using flash image how it is overlayed in jsp page?
thanks
changing uiview background colorchanging uiview
background color changing UIView
background color in ios
self.view.backgroundColor = [UIColor colorWithRed:244.0f/255.0f green:230.0f/255.0f blue:183.0f/255.0f alpha:1.0f
UITableViewCell background imageUITableViewCell
background image Hi,
I am developing UITable based iPhone application. I have to add the
background image to UITableViewCell. Please tell me how to add UITableViewCell
background image.
Thanks
Hi
jframe background color not showingjframe
background color not showing jframe
background color is not showing. please suggest.
Just add the
background color to JPanel and then add it to JFrame. For example ..
JFrame myFrame = new JFrame();
JPanel
Background image UIBarButtonItemBackground image UIBarButtonItem i wanted to add a
background image to my UIBarButtonItem.. that i created into .xib in my iPhone application.
Set the
background image to UIBarButtonItem
UIBarButtonItem *btn
uinavigationcontroller background imageuinavigationcontroller
background image I wants to add a
background... a
background image to uinavigationcontroller... the
Background Image to it as given belowâ?¦
#import <UIKit/UIKit.h>
#import <
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 ImageUITextField
Background Image How can i set a
background image on UITextField. I have placed that UITextField on UIToolBar.
Code to Set a
Background Image on UITextField
- (void)viewDidLoad {
[super viewDidLoad
HTML - table background color.HTML - table
background color.
Description :
Here, you will see how to specifies the table back ground color in html page.
The <table > is a html... the
background color of table.
Code :
<!DOCTYPE html PUBLIC "