• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList Item Not Getting Mouse Clicks

 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11165
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Derek Boring
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11165
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic