icon.java

来自「模仿腾讯QQ的」· Java 代码 · 共 61 行

JAVA
61
字号
package com.softfz.jn0708.main.user;

/*
 * 实现渲染器,加载下拉框图片
 */

import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 * 实现渲染器,加载下拉框图片
 * @author admin
 *
 */

public class Icon extends JLabel implements ListCellRenderer {

	
	private static final long serialVersionUID = 1L;
	
	private String fileName ;
	
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		
		if (value!=null){
			
			
//			File file=new File("./src/com/softfz/jn0708/images/face/");		
//			File[] fileList=file.listFiles();	
//			for (int i=0;i<fileList.length;i++){
//				URL url = Images.class.getResource("face/"+fileList[i].getName());
//				ImageIcon icon  = new ImageIcon(url);	
//			}	
			
			fileName=value.toString();			
			setIcon(new ImageIcon("./images/head/"+fileName));
			
		}
		if (isSelected){
			this.setBackground(list.getSelectionBackground());
			this.setForeground(list.getSelectionForeground());
		}else{
			this.setBackground(list.getBackground());
			this.setForeground(list.getForeground());
		}
		
		this.setBorder(BorderFactory.createEmptyBorder(3,3,0,3));
		this.setOpaque(true);
		
		return this;
	}




}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?