I'm developing a desktop app using JDK 1.7.0 on a Windows 7 machine, not that that should matter. My question is about parameterized types and specifically a ListCellRenderer for a JList. I have included both an example of the the warnings I am receiving and the code that the compiler is complaining about.
I admit that I'm still very new to Swing and not all that comfortable with parameterized types beyond simple cases. Any words of wisedom regarding these warnings will be appreciated as will recommendations for a good tutorial on parameterized types.
warning: [unchecked] unchecked call to setCellRenderer(ListCellRenderer<? super E>) as a member of the raw type JList
scrollingList.setCellRenderer(new MyListCellRenderer());
where E is a type-variable:
E extends Object declared in class JList
class MyListCellRenderer extends JLabel implements ListCellRenderer<Object> { public MyListCellRenderer() { setOpaque(true); } @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(((JLabel)value).getText()); setIcon(((JLabel)value).getIcon()); Color background; Color foreground; // check if this cell represents the current DnD drop location JList.DropLocation dropLocation = list.getDropLocation(); if (dropLocation != null && !dropLocation.isInsert() && dropLocation.getIndex() == index) { background = Color.PINK.darker(); foreground = Color.CYAN.brighter(); } else if (isSelected) { background = list.getSelectionBackground(); foreground = list.getSelectionForeground(); } else { background = Color.WHITE; // getBackground is ugly foreground = list.getForeground(); } setBackground(background); setForeground(foreground); return this; } }