KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > chateverywhere > SimpleLabelCellRenderer


1
2 package org.chateverywhere;
3
4
5 import java.awt.*;
6 import javax.swing.*;
7
8
9 public class SimpleLabelCellRenderer implements ListCellRenderer
10 {
11
12     public Component getListCellRendererComponent(
13      JList list,
14      Object JavaDoc value,
15      int index,
16      boolean isSelected,
17      boolean cellHasFocus)
18     {
19         JLabel me = (JLabel) value;
20         
21         //me.setOpaque(true); // dedicated to the parent...
22

23         if(isSelected) {
24             me.setForeground(list.getSelectionForeground());
25             me.setBackground(list.getSelectionBackground());
26         } else {
27             me.setForeground(list.getForeground());
28             me.setBackground(list.getBackground());
29         }
30
31         return me;
32     }
33 }
34
Popular Tags