Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes JComboBox Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JComboBox Problem " Watch "JComboBox Problem " New topic
Author

JComboBox Problem

manish basotia
Ranch Hand

Joined: Jan 12, 2004
Posts: 47
Dear Friends
I have a combobox say it contains the following elements
Arial
Courier
Arjun
windings
verdana
default
dialog
*************
Now i have a list which contains
Arial
Courier
Arjun
******
My problem is that in the combobox those elements which are not there in the list must be displayed in RED Color.
Please help me its urgent.
I tried to use ListCellRenderer, but it makes all the elements as RED
Here i just tried to diplay arial and arjun fonts in RED. its not working
class MyCellRenderer extends JLabel implements ListCellRenderer{
public MyCellRenderer(){
setOpaque(true);
}
public Component getListCellRendererComponent(JList list,
Object value,int index, boolean isSelected,boolean cellHasFocus)
{
setText(value.toString());
if(value.toString().equals("Arial"))
{
setBackground(getBackground());
setForeground(Color.red);
System.out.println("In if ......");
}
if(value.toString().equals("Arjun")) {
setBackground(getBackground());
setForeground(Color.red);
System.out.println("In if ......");
}else {
setBackground(getBackground());
setForeground(Color.black);
System.out.println("In else ......");
}
return this;
}
}
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

I don't see anything obvious in your code. Try using this renderer:

If you don't get red and black alternating entries, the problem is elsewhere in your code.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JComboBox Problem
 
Similar Threads
Color in JComboBox
JComboBox item rendering
How to create border or change color in a JTable cell?
ListCellRenderer
compilation error ,ListCellRenderer implementaion for Jtable