owncellrenderer.java

来自「这是一个简单的图书管理系统,适用于教学中演示,讲解java高级编程语言」· Java 代码 · 共 45 行

JAVA
45
字号
package helpfile;import javax.swing.ListCellRenderer;import java.awt.Component;import javax.swing.JList;import javax.swing.*;import java.awt.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class OwnCellRenderer extends JLabel implements ListCellRenderer {  private Icon[] icons;  public OwnCellRenderer(Icon[] icons) {    this.icons = icons;    this.setOpaque(true);    this.setFont(new Font("Dialog",Font.PLAIN,16));  }  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {    /**@todo Implement this javax.swing.ListCellRenderer method*/    if(value!=null){        String text = value.toString();        this.setText(text);    }    this.setIcon(icons[index]);    if(isSelected){        this.setBackground(list.getSelectionBackground());        this.setForeground(list.getSelectionForeground());    }    else{        this.setBackground(list.getBackground());        this.setForeground(list.getForeground());    }    return this;    //throw new java.lang.UnsupportedOperationException("Method getListCellRendererComponent() not yet implemented.");  }}

⌨️ 快捷键说明

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