I've not tested this, but the basics would be...
- Use
JList#locationToIndex(Point)
to get the index of the element at
the given point.
- Get the "element" at the specified index (using
JList#getModel#getElementAt(int)
).
- Get the
ListCellRenderer
using JList#getCellRenderer
.
- Render the element and get it's
Component
representation
- Set the renderer's bounds to the required cell bounds
- Convert the original
Point
to the Component
s context
- Use
getComponentAt
on the renderer...
Possibly, something like...
int index = list.locationToIndex(p);
Object value = list.getModel().getElementAt(int);
Component comp = listCellRenderer.getListCellRendererComponent(list, value, index, true, true);
comp.setBounds(list.getCellBounds(index, index));
Point contextPoint = SwingUtilities.convertPoint(list, p, comp);
Component child = comp.getComponentAt(contextPoint);
JList
, add aListSelectionListener
. For better help sooner, post an SSCCE. – LarisaJList
does not container any components. It uses theListCellRenderer
to paint a "rubber stamp" of the component onto the list. That is, each element in the list is rendered using the same/singleListCellRenderer
– Oxytetracycline