File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JList Item Not Getting Mouse Clicks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList Item Not Getting Mouse Clicks" Watch "JList Item Not Getting Mouse Clicks" New topic
Author

JList Item Not Getting Mouse Clicks

Derek Boring
Ranch Hand

Joined: Aug 15, 2006
Posts: 63
Hello,

I have a JList with custom components as the items and a custom renderer. The components show properly, but I'm trying to make them turn into a JTextArea when they are double clicked so the user can edit the item's text. The problem is, I added a mouse listener to each component, but the events are not getting fired.

The custom components consist of 7 JLabels that must turn into JTextAreas when double clicked. The layout is GridLayout(1,7)

Does anybody know how I can make it work or if there is a workaround?

Thanks in advance.


Life is 10% what happens and 90% how you react to it.
Attitude is everything.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Originally posted by Derek Boring:
Hello,
..I added a mouse listener to each component, but the events are not getting fired.


Add the listener to the JList. Then you can figure out which component was selected and then in turn call some method on the selected component to do the stuff you want.
A renderer is not a real component in the physical sense. It is just the paint method tweaked to make it look like a component.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Derek Boring:
I have a JList with custom components as the items and a custom renderer. The components show properly, but I'm trying to make them turn into a JTextArea when they are double clicked so the user can edit the item's text. The problem is, I added a mouse listener to each component, but the events are not getting fired.

The custom components consist of 7 JLabels that must turn into JTextAreas when double clicked. The layout is GridLayout(1,7)

Does anybody know how I can make it work or if there is a workaround?


It sounds like you don't really want a JList with custom renderer, but
rather seven actual components in a panel, right?

If you intend to use JList, then its items aren't really Components
in any conventional sense. Rather, renderer component(s) is/are
used (briefly) when the items need to be drawn on the screen. I'm
also not sure how GridLayout(1,7) would pertain.


bitguru blog
Derek Boring
Ranch Hand

Joined: Aug 15, 2006
Posts: 63
Thanks, that answers it, but also brings up another question: When I change the JLabels into JTextAreas, will the user be able to type into the JTextAreas?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Originally posted by Derek Boring:
Thanks, that answers it, but also brings up another question: When I change the JLabels into JTextAreas, will the user be able to type into the JTextAreas?


That would depend on if the cell is set to editable true.
I think I can imagine how you want the UI to look and perform. I had tried something similar long time back. However at that time I was adding my panel to a JPopupMenu and displaying it.

You might want to consider this approach if you feel it suits your requirement better.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Derek Boring:
brings up another question: When I change the JLabels into JTextAreas, will the user be able to type into the JTextAreas?


If you add the JTextAreas directly to the panel/container, then
teh user will be able to type into it. If you're still talking
about JList renderers, then no. JList doesn't have the concept
of editors as JTable does.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList Item Not Getting Mouse Clicks