aspose file tools*
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: 8997
    
    9

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.


[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JComboBox Problem