Yes, you've misunderstood something about ListCellRender -- it only renders / paints.  
If you want the components to be live, you'll need to do something else.

You could try to make your Jlist more live by adding mouse and other event listeners 
to the Jlist and then repainting with button pressed status, etc.  This would be some 
hassle.  Some alternate approaches to this would be to automatically start editing the 
row when it's clicked.  The cell editor component is actually added and used as a 
child component during editing (unlike the cell renderer which only draws).  Thus a 
cell editor (which might even be the same object as your renderer) can handle things 
like button presses, etc.

Another approach might be to skip JList.  Instead, create a grid of row objects and 
use a fake scrollbar to switch the data displayed in each row to look like a scrolling 
list (which scrolls entire rows at a time, rather than at the pixel level).  In this 
way, you could have live components for each row at the price of creating more 
components and possibly complicating the listening / editing process?

If your row object is very complicated, perhaps a different UI is in order?  Using a 
table instead of a Jlist and/or combination of other things?

Joel

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 10, 2003 9:00 AM
To: [EMAIL PROTECTED]
Subject: JList and CellRenderer problem




Hi all,

I've coded my own MyCellRenderer as an inner class which implements
ListCellRenderer interface. I'm using this to display a JList.   (ie.
MyJList.setCellRenderer(MyCellRenderer) );

My "public Component getListCellRendererComponent(JList list, Object value, int index, 
boolean isSelected, boolean cellHasFocus)" method returns a JPanel which uses a 
GridLayout(4,1) to display a set of Components for each row of the JList
- the components within the JPanel are two JLabels, aJComboBox and a JButton.

The code runs fine, and I get a JList rendered exactly how I want.

However - none of the Components in the JList are usable by the user.  8(

The JComboBoxes won't expand to show the possible selections and the JButtons won't 
depress and release when I click them with the mouse. (I've added an anonymous 
actionPerformed(ActionEvent e) to each JButton which simply prints "Hello" when any 
button is pressed, but I interacting with the buttons doesn't generate that message).

Have I misunderstood something about ListCellRenderer ? It seems that you can only set 
the way the JList is shown to the user, but can't interact with any of the components 
returned by the getListCellRendererComponent method?

thanks in advance for any help,

     andy




**********************************************************************
This e-mail has been sent from a PC belonging to DSG Retail Limited or another company 
in the Dixons Group, registered office Maylands Avenue, Hemel Hempstead, Hertfordshire 
HP2 7TG.  Its contents are confidential to the sender and the intended recipient.

If you receive it in error, please tell us by return and then delete it from your 
system;  you may not rely on its contents nor copy/disclose it to anyone.

Opinions, conclusions and statements of intent in this e-mail are those of the sender 
and will not bind a Dixons Group company unless confirmed by an authorised 
representative independently of this message.  We do not accept responsibility for 
viruses;  you must scan for these.

Please note that e-mails sent to and from the Dixons Group are routinely monitored for 
record keeping, quality control and training purposes, to ensure regulatory compliance 
and to prevent viruses and unauthorised use of our computer systems.

_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED] http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to