This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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: 8915
    
    8

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]
 
GeeCON Prague 2014
 
subject: JComboBox Problem