How to render a JCheckBox on cells of JList?  
Author Message
MaoXuePeng





PostPosted: 2004-10-14 16:13:00 Top

java-programmer, How to render a JCheckBox on cells of JList? 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.


 
David Harper





PostPosted: 2004-10-15 3:10:00 Top

java-programmer >> How to render a JCheckBox on cells of JList? > I do it like this:
>
[SNIP]
>
> However, there is a problem: I can not select or disselect those check box
> rendered in the JList.
> What wrong?

You might get a better response if you posted this query to
comp.java.lang.gui which is where the Swing dudes hang out.

David Harper
Cambridge, England