![JAR search and dependency download from the Maven repository](/logo.png)
bc.ui.swing.lists.StripeListItemRenderer Maven / Gradle / Ivy
/*
* The MIT License
*
* Copyright 2016 Benny Lutati.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package bc.ui.swing.lists;
import bc.ui.swing.visuals.Visual;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.FontMetrics;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
/**
*
* @author bennyl
*/
public class StripeListItemRenderer extends javax.swing.JPanel implements ListCellRenderer {
private Color selectionBackColor = new Color(51, 153, 255);
private Color selectionForeColor = new Color(245, 245, 245);
private Color evenBackColor = new Color(245, 245, 245);
private Color evenForeColor = new Color(51, 51, 51);
private Color oddBackColor = new Color(215, 215, 215);
private Color oddForeColor = new Color(71, 71, 71);
/** Creates new form StripeListItemRenderer */
public StripeListItemRenderer() {
initComponents();
}
@Override
public void setFont(Font font) {
if (text != null) {
text.setFont(font);
}
}
@Override
public Font getFont() {
if (text == null) {
return super.getFont();
}
return text.getFont();
}
public Color getEvenBackColor() {
return evenBackColor;
}
public void setEvenBackColor(Color evenBackColor) {
this.evenBackColor = evenBackColor;
}
public void setSelectionForeColor(Color selectionForeColor) {
this.selectionForeColor = selectionForeColor;
}
public void setSelectionBackColor(Color selectionBackColor) {
this.selectionBackColor = selectionBackColor;
}
public Color getSelectionForeColor() {
return selectionForeColor;
}
public Color getSelectionBackColor() {
return selectionBackColor;
}
public Color getEvenForeColor() {
return evenForeColor;
}
public void setEvenForeColor(Color evenForeColor) {
this.evenForeColor = evenForeColor;
}
public Color getOddBackColor() {
return oddBackColor;
}
public void setOddBackColor(Color oddBackColor) {
this.oddBackColor = oddBackColor;
}
public Color getOddForeColor() {
return oddForeColor;
}
public void setOddForeColor(Color oddForeColor) {
this.oddForeColor = oddForeColor;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
text = new javax.swing.JLabel();
setMinimumSize(new java.awt.Dimension(59, 26));
setPreferredSize(new java.awt.Dimension(59, 26));
setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 3, 3));
text.setFont(new java.awt.Font("Consolas", 0, 12)); // NOI18N
text.setText("jLabel1");
add(text);
}// //GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel text;
// End of variables declaration//GEN-END:variables
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (isSelected) {
setBackground(selectionBackColor);
text.setForeground(selectionForeColor);
} else {
if (index % 2 == 0) {
setBackground(evenBackColor);
text.setForeground(evenForeColor);
} else {
setBackground(oddBackColor);
text.setForeground(oddForeColor);
}
}
text.setText(value.toString());
if (value instanceof Visual) {
text.setIcon(((Visual) value).getIcon());
} else {
text.setIcon(null);
}
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy