1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public class MyCellRenderer2 extends JLabel implements ListCellRenderer2 {
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 has focus
{ return this; }
public Component getListCellRendererComponent (
JList list,
Vector<Vector> value, //list to display
int index, //cell index
boolean isSelected, //is the cell selected
boolean cellHasFocus) //the list and the cell has focus
{
//process the component content (a string)
String s = list.toString();
//set the text with setText inherited from JLabel
//sets the selected display
if (isSelected){
setBackground(Color.BLUE);
setForeground(list.getSelectionForeground());
} else {
//sets the non selected display
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
/**
* display component with font size according to priority level
* conditional formatting:
* priority 1 : font size = 16
* priority 2 : font size = 12
* priority 3 : font size = 8
*/
for (int i = 0; i < value.size(); i++){
Vector<String> font = new Vector<String>();
font = value.elementAt(i);
setFont(new Font("Arial Bold", Font.PLAIN, new Integer(font.elementAt(1))));
}
setOpaque(true);
return this;
}
} |
Partager