本帖最后由 Willam2004 于 2010-03-01 13:53:05 编辑

解决方案 »

  1.   

    没人回答:可能是我问题描述的不清楚:
    我具体点:
    JLIst中,我自己写了ListCellRenderer的一个实现,他的getListCellRendererComponent方法,我返回了一个JPanel,上面有两个JLabel,默认时只显示一个JLabel,选中时全部显示,问题是,当我运行时,选中一个项时,该列表项的高度没有改变。不知道有没有知道该如何解决这个问题?public class MyCellRender extends JPanel implements ListCellRenderer {
    private JLabel contentLabel;

    private JLabel tipLabel;


    public MyCellRender(){
    super();
    contentLabel = new JLabel();
    tipLabel = new JLabel();
    this.setLayout(new BorderLayout());
    this.add(contentLabel, BorderLayout.NORTH);
    this.add(tipLabel, BorderLayout.CENTER);
    } @Override
    protected void paintComponent(Graphics g) {
    // TODO Auto-generated method stub
    // super.paintComponent(g);
    }
    public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus) {
    // TODO Auto-generated method stub
    String str = (String)value;
    contentLabel.setText(str);
    if(isSelected){
    tipLabel.setText("ToolTip" + str);
    }else{
    tipLabel.setText("");
    }
    //设置背景选择颜色
    ListRenderUtil.setColorForSelectionState(this, isSelected);
    //设置透明度
    ListRenderUtil.opacify(this);
    return this;
    }
    }