• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why doesn't a component in a Listbox see mouse clicks when using a DefaultListCellRenderer ?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a listbox which contains a custom component consisting of a panel which in turn contains other panels.

The listbox has a DefaultListCellRenderer which tells me when the component has focus, is selected etc.

But, the mouse clicks on the component (my Panel(s)) are not 'seen' by the component.

My renderer only implents getListCellRendererComponent.

Should I be implementing some other methods in the renderer or ???

Thanks
Jim


 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A renderer is NOT a real component. It only paints an image of a component, so it does not receive events.

If you have multiple nested panels it sounds like you should be using a panel with a BoxLayout and just use real panels.

Or if you have multiple components, maybe you should be using a JTable with individual columns for each piece of data.
 
Jim McGlaughlin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The 'panels' I am putting in the listbox start with a panel which does use the BoxLayout.

If I don't use the renderer the panels will not display, just Strings that describe the panels.

A JTable would be a step back from what I was hoping to have as a user interface.

Do you know if I implement a mouse listener, if it would be practical to pass the click points to the underlying panel ? I don't think so.

I'm going to have to re-think my user interface.

Thanks
Jim
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do it the hard way as well:
1) use the API to get the row on which the user clicked
2) use the cell renderer to get the renderer component for that cell
3) translate the mouse point such that it is relative to the renderer component
4) handle the mouse click manually given the translated mouse point

I've done this for a table and a tree renderer in the past, and it works.
 
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic