
org.swixml.list.CustomListCellRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swixml-quickstart Show documentation
Show all versions of swixml-quickstart Show documentation
Project to define a maven swixml-quickstart archetype
The newest version!
package org.swixml.list;
import java.awt.Component;
import java.util.logging.Level;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.swixml.LogAware;
@SuppressWarnings("serial")
public class CustomListCellRenderer extends JLabel implements ListCellRenderer, LogAware {
public CustomListCellRenderer() {
super();
Application app = Application.getInstance();
try {
ResourceMap res = app.getContext().getResourceMap();
Icon icon = res.getIcon( "listIcon");
if( null!=icon ) {
super.setIconTextGap(6);
super.setIcon(icon);
}
}
catch( Exception ex ) {
logger.log( Level.WARNING, "icon doesn't exist", ex );
}
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
String s = value.toString();
setText(s);
//setIcon((s.length() > 10) ? longIcon : shortIcon);
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
setOpaque(true);
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy