java - Get a component from JList by click location -



java - Get a component from JList by click location -

how can fetch component jlist, click location?

i have own list cell renderer insert panels , labels. want e.g. label user clicked at.

i tried method list.getcomponentat(evt.getpoint()); returns entire jlist.

i've not tested this, basics be...

use jlist#locationtoindex(point) index of element @ given point. get "element" @ specified index (using jlist#getmodel#getelementat(int)). get listcellrenderer using jlist#getcellrenderer. render element , it's component representation set renderer's bounds required cell bounds convert original point components context use getcomponentat on renderer...

possibly, 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 kid = comp.getcomponentat(contextpoint);

java swing location selection jlist

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -