I create a JList by passing it an array of data
public class MyJList extends JList() {
...
public MyJList(final Object[] listData) {
super[listData];
}
I render this list using the ListCellRenderer, which provides me a Component for each item, which can be enabled or disabled according to buisness logic.
The problem comes when I try to navigate by keyboard arrows. I want the disabled items skipped. (go on to the next one in the appropriate direction) I have to use a KeyboardListener, because the UI changes some things depending on which item is selected on the list. Trouble is, in the keyboard listener, I cannot get the COMPONENT of the item with the selected index. This Component is not owned by the JList, and calling MyJList.getComponent(index) fails with an ArrayIndexOutOfBoundsException. 1 is too large an index, even though I can see seven items, four of which are enabled.
How can I programatically retreive a component by index from my JList to determine if it's enabled? The only interface that seems to return a Component is getListCellRendererComponent() - which changes the display of the component. I just want to get the component to see if it's enabled.