Results 1 to 3 of 3
Thread: AdjustmentListener - Question
- 12-12-2010, 12:01 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
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();
switch (type)
{
case AdjustmentEvent.UNIT_INCREMENT: // Scrollbar was increased by one unit
currentListPlacementFocus=currentListPlacementFocu s+1; // global value
break;
case AdjustmentEvent.UNIT_DECREMENT: // Scrollbar was decreased by one unit
currentListPlacementFocus=currentListPlacementFocu s-1;
break;
}
}
if(currentScrollPane.contains(source)){
// SET THE DEFAULT LIST VIEW TO THE HIGHEST NUMBER
Point p = currentJlistArrayItem.get(sourceIndex).indexToLoca tion(currentListPlacementFocus);
JViewport port = currentScrollPane.get(sourceIndex).getViewport();
port.setViewPosition(p);
currentJlistArrayItem.get(sourceIndex).setSelected Index(currentListPlacementFocus);
}
}
Any feedback would be appreciated. This is my first post. I apologize for any formatting issues.
- 12-13-2010, 07:08 AM #2
To get better help sooner, post a SSCCE that clearly demonstrates your problem.here is code snippet of adjustmentlistener method:
Use code tags to post codes -- [code]CODE[/code] will display asdbJava Code:CODE
- 12-15-2010, 09:14 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Question concerning question marks and colons
By jim01 in forum New To JavaReplies: 17Last Post: 01-14-2011, 12:05 AM -
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM -
Question
By vittoire in forum New To JavaReplies: 3Last Post: 02-02-2010, 12:54 PM -
Question
By ayoood in forum New To JavaReplies: 16Last Post: 05-21-2008, 02:23 PM -
Demonstrating the AdjustmentListener
By Java Tip in forum java.awtReplies: 0Last Post: 04-23-2008, 08:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks