最近在编一个小程序 用swing实现界面 
想把那些多选项按钮改进一下
全部改成图片的形式,按下图片 图片会外发光代表选上,再按一次外发光消失代表没选上
想不出什么比较好的实现方式,大家有没有什么意见

解决方案 »

  1.   

    public class MemoTypeListItemButton extends JButton implements ListCellRenderer<Object> {
    private ImageIcon icon = null; public MemoTypeListItemButton() {
    super();
    initialize();
    } /**
     * This method initializes this
     * 
     */
    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 = value.toString();
            icon = new ImageIcon("src/image/"+(index+1)+".png");
            setText(title);
            setIcon(icon);
            if (isSelected) {
                setBackground(new Color(18,165,199));
            } else {
                setBackground(new Color(211,239,243));//这里设置不同的颜色
            }
    return this;
    }
    }
    这个代码只是提示,希望帮到你