How to render a JCheckBox on cells of JList?

From: MaoXuePeng (mxp123q_at_126.com)
Date: 10/14/04

  • Next message: Ike: "Inner Join / Indexes Hell"
    Date: Thu, 14 Oct 2004 04:13:26 -0400
    
    

    I do it like this:

    public class CheckBoxCellRenderer extends JCheckBox implements
    ListCellRenderer {

      public CheckBoxCellRenderer() {
        super();
      }
      public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus) {
        
        if(isSelected)
        {
          this.setForeground(java.awt.Color.BLUE);
          
        }
        this.setEnabled(isSelected);
        this.setText("Hello");
        return this;
      }

    However, there is a problem: I can not select or disselect those check box
    rendered in the JList.
    What wrong?

    Thanks.
    MaoXuePeng.


  • Next message: Ike: "Inner Join / Indexes Hell"