I can't believe this does not work.
I have a JList. I have set its renderer as follows. Basically RankingPanel
is a JPanel with two labels and a button.
topAchieverList = new JList();
topAchieverList.setCellRenderer(new TopBottomCellRenderer());
Here is my TopBottomCellRenderer.
class TopBottomCellRenderer extends RankingPanel implements ListCellRenderer {
public TopBottomCellRenderer() {
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
try {
Achievers achiever = (Achievers) value;
if (achiever == null) {
return this;
}
itemRank.setText("#" + achiever.rank);
itemUnits.setText("" + achiever.units);
//this is the button that does not click
itemNameButton.setText(achiever.name);
//set bg
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
return this;
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
}
The list renders properly but the JButton
is not clickable. Clicking it does nothing.
How do I make this work?
RankingPanel
objects to aJPanel
which i added to a `JScrollPane'. Thanks for the help. – Possing