Created
February 10, 2015 11:42
-
-
Save nilsding/b76faa583fe9f4a90718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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