This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

compilation error ,ListCellRenderer implementaion for Jtable  RSS feed

 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried to use this sample which is there on java doc.
But I am getting a compilation error as:
The method Component getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean) declared in class MyCellRenderer cannot override the method of the same signature declared in interface javax.swing.ListCellRenderer. They must have the same return type.

I am puzzled any help?
//************************************
import javax.swing.*;
class MyCellRenderer extends JLabel implements ListCellRenderer {
//final static ImageIcon longIcon = new ImageIcon("long.gif");
// final static ImageIcon shortIcon = new ImageIcon("short.gif");
// This is the only method defined by ListCellRenderer. We just
// reconfigure the Jlabel each time we're called.
public MyCellRenderer() {
setOpaque(true);
}
public Component getListCellRendererComponent(
JList list,
Object value, // value to display
int index, // cell index
boolean isSelected, // is the cell selected
boolean cellHasFocus) // the list and the cell have the focus
{
//String s = value.toString();
//setText(s);
//setIcon((s.length() > 10) ? longIcon : shortIcon);
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
}
else {
//setBackground(list.getBackground());
setBackground(Color.white);
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
return (this);
}
}
thanks in advance,
Mohana
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!