Results 1 to 3 of 3
  1. #1
    jfPen72 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default 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.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    here is code snippet of adjustmentlistener method:
    To get better help sooner, post a SSCCE that clearly demonstrates your problem.

    Use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:
    CODE
    db

  3. #3
    jfPen72 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Thanks. I will do so in the future. I kind of have this working now so I think I'm ok at this point.

    Thank you for the reply and tip.

    pen72

Similar Threads

  1. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 12:05 AM
  2. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  3. Question
    By vittoire in forum New To Java
    Replies: 3
    Last Post: 02-02-2010, 12:54 PM
  4. Question
    By ayoood in forum New To Java
    Replies: 16
    Last Post: 05-21-2008, 02:23 PM
  5. Demonstrating the AdjustmentListener
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 04-23-2008, 08:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •