My apologies if this has been answered elsewhere, I failed to find it if it had been.
I have a swing app that has a text area populated by action handler for one jlist, a section list ( inside a scroll pane, inside a splitpane ) which is populated by the action handler for another jlist, a chapter list ( likewise in a scroll pane inside other half of splitpane ) all of which are in a jframe.
THe problem is that on first launch, I can change the careted selection in either jlist using the keyboard, and tab between all three components, but no action is taken until I click into each component.
the chapter list doesn't react until I click into it, so the section list doesn't react. I click into the section list and finally things begin to shake. Only once I've /clicked/ into /both/ the chapter list and the section list can I expect the text area to change by navigating the chapter list.
I am requesting focus into the chapter list and giving it a selected index upon building the GUI.
-------<br /> Aodhan H - Ad Astra Per Aspera<br /> -------
jlChapterList.setSelectedIndex(0); jlChapterList.requestFocus();// set focus on chapter list
frame.setVisible( true ); // make window visible But while the first list entry is highlighted, and using the arrow keys changes selection, there's no action registered. My action handler for the jlist ( public void valueChanged( ListSelectionEvent e ) ), only fires once I've clicked into the component.
I'm know this is a relatively common mistake/problem, but I don't see any answers beyond what I've already done.
It's not a mistake and calling it a problem is probably relative to everyone's situation. The JList component was built this way on purpose. The only way to fire the event for the JList is by hitting the enter key or clicking it with the mouse.
The only other way around this that I know of is you would have to create a FocusListener and add that listener to each item in your JList's model. Then on focusGained() you can do whatever you want to do about that item being selected.