I have a JList with a JScrollPane. If I only have one thing in the JList, there will be empty space due to the JScrollPane. If I click anywhere in the JList, it will click the one element. Is there a way to make it only click the element if I actually click it? Also, I am using a custom renderer for the JList to add images, if that has anything to do with it.
Thanks
You can check the index that was clicked via locationToIndex.
Returns the cell index closest to the given location in the list's coordinate system. To determine if the cell actually contains the specified location, compare the point against the cell's bounds, as provided by
getCellBounds. This method returns-1if the model is empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With