• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JComboBox Problem

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
}
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
catch it before it slithers away! Oh wait, it's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic