src/com/zzk/list/button/SortListItemButton.java

(完整代码) 1KB

package com.zzk.list.button;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class SortListItemButton extends JButton implements ListCellRenderer {
    private ImageIcon icon = null;

    public SortListItemButton() {
        super();
        initialize();
    }

    private void initialize() {
        this.setSize(new Dimension(110, 31));

    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        String title = (String) value;
        icon = new ImageIcon("src/image/" + (index + 1) + ".png");
        setText(title);
        setIcon(icon);
        if (isSelected) {
            setBackground(new Color(223, 206, 98));
        } else {
            setBackground(new Color(240, 238, 225));
        }
        return this;
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。