AdjustmentListener - Question
I have an ArrayList of JScrollPanes. These are accompanied by ArrayLists of JLists, JButtons for creating a dynamic GUI populated by a datasheet.
The JLists vary. Only 1 item is visible on screen for a given JList and the user can click the up/down arrow keys on the jscrollpane to navigate the lists. I default the selected item and item that is visible for any given list to = the "highest number" based on the data. I am using viewport and setselected to achieve this.
This part is working. My problem is that I want the user to be able to click the up/down arrow key and have the item in the JList to auto select based on whichever item is currently in view.
I have been attempting to achieve this via AdjustmentListener. I have added the adjustmentListener to the various JScrollpanes and I am getting into the method. However, the adjustment type is always 5 (increment, even though I attempt to decrement). It is not taking... It could be that I am attempting to use the wrong listener. Any ideas would be appreciated?
here is code snippet of adjustmentlistener method:
public void adjustmentValueChanged(AdjustmentEvent evt)
Adjustable source = evt.getAdjustable();
int sourceIndex = jlPlaceUnit_cerathax.indexOf(source);
if(currentScrollPane.contains(source) // currentScrollPane is the ArrayList
// Determine the type of event
int type = evt.getAdjustmentType();
case AdjustmentEvent.UNIT_INCREMENT: // Scrollbar was increased by one unit
currentListPlacementFocus=currentListPlacementFocu s+1; // global value
case AdjustmentEvent.UNIT_DECREMENT: // Scrollbar was decreased by one unit
// SET THE DEFAULT LIST VIEW TO THE HIGHEST NUMBER
Point p = currentJlistArrayItem.get(sourceIndex).indexToLoca tion(currentListPlacementFocus);
JViewport port = currentScrollPane.get(sourceIndex).getViewport();
Any feedback would be appreciated. This is my first post. I apologize for any formatting issues.