Skip to content

Instantly share code, notes, and snippets.

@nilsding
Created February 10, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsding/b76faa583fe9f4a90718 to your computer and use it in GitHub Desktop.
Save nilsding/b76faa583fe9f4a90718 to your computer and use it in GitHub Desktop.
import java.awt.Color;
import java.awt.Component;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.LineBorder;
/**
*
* @author nilsding
*/
public class ListZellRenderer extends javax.swing.JLabel implements ListCellRenderer<Integer> {
@Override
public Component getListCellRendererComponent(JList<? extends Integer> jlist, Integer val, int i, boolean isSelected, boolean hasFocus) {
this.setOpaque(true);
this.setText(String.format("%d", val));
this.setHorizontalAlignment(javax.swing.JLabel.RIGHT);
if (isSelected) {
this.setBackground(jlist.getSelectionBackground());
this.setForeground(jlist.getSelectionForeground());
}
if (hasFocus) {
this.setBorder(new LineBorder(jlist.getSelectionForeground()));
}
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment