JScrollpane, scroll to selected element

I have a JList of years inside a JScrollPane. The size of the scrollpane is the height of one row, so you can only see one year at a time. If the selected element in the list is changed, I want the ScrollPane to move to the selected element.
It was suggested to me that I use the methods
scrollRectToVisible()
and
getCellBounds()
but I can't get that to work.
Here is just a rough bit of code using these functions:
import java.awt.*;
import javax.swing.*;
public class test {
     public static void main(String[] args) {
          JList selectYear;
          DefaultListModel selectYearModel;
          JScrollPane selectYearScrollPane;
          selectYearModel = new DefaultListModel();
          selectYear = new JList(selectYearModel);
          selectYear.setFixedCellHeight(25);
          selectYearScrollPane = new JScrollPane(selectYear);
          selectYearScrollPane.setPreferredSize( new Dimension(100, 25) );
          for(int i=1800; i<2200; i++) {
               selectYearModel.addElement(""+i);
          selectYear.setSelectedIndex(5);
          selectYearScrollPane.scrollRectToVisible( selectYear.getCellBounds(selectYear.getSelectedIndex(), selectYear.getSelectedIndex()) );
          JFrame myFrame = new JFrame();
          myFrame.setVisible(true);
          myFrame.add(selectYearScrollPane);
          myFrame.pack();
}If you run this you will see that the selected index is not scrolled to.

I have a JList of years inside a JScrollPane. The
size of the scrollpane is the height of one row, so
you can only see one year at a time.Then you shouldn't use a JList. A JSpinner seems more appropriate.
If the selected
element in the list is changed, I want the ScrollPane
to move to the selected element.
It was suggested to me that I use the methods
scrollRectToVisible()
and
getCellBounds()
ensureIndexIsVisible(int index) might work better.

Similar Messages

  • Error Rendering SELECT Element in Safari Under iOS (iPhone & iPad)

    Hello,
    Our website contains three SELECT elements that are not rendering properly under Safari, iOS 4.2 on both an iPhone and iPad.
    If you load http://demo.campusguides.com in a normal browser (Chrome, FF, non-mobile Safari) you will see that the three "Browse By" boxes at the top of the page each contain text that you can select using your mouse. Each of those boxes is actually a SELECT element and each piece of text is an OPTION within that SELECT box. We have set a SIZE property on the SELECT element that allows the user to see more than one OPTION value at a time. Here is the W3C page that mentions the SIZE option for SELECT boxes - http://www.w3.org/TR/html401/interact/forms.html#adef-size-SELECT.
    On all the browsers I have tested the list displays properly, meaning that you can see multiple OPTION values at once as well as a scroll bar (when needed) that allows you to scroll up and down the list. On iOS Safari however the list is displayed as an empty box with no OPTION values visible to the user. If the iOS user clicks the SELECT element they are taken to the normal SELECT interface for Safari which does work fine, but without any content displaying in the box to begin with, I don't think many users would know they can / should click that element.
    So basically I think this is a bug, and that iOS Safari should either render that SELECT element with the OPTIONS visible to the user, or it should ignore the SIZE property and render that element like a "normal" SELECT menu where only one option is visible at a time.
    Thank you!

    Check here for Safari HTML guidelines: Safari HTML Reference
    If you regard the seen behavior as a bug then report it to Apple at: Bug Report Form
    Note: This is a user-to-user forum. You might get better response in the developers forums.

  • Get selected elements from a table

    Hi all,
    I have a requirement like i m enhancing standard component in that i have added one button on click of that i want fetch the selected line item from the table ( which is a normal table). selection mode is auto.
    i tried with  the following code.
    DATA:lr_element                   TYPE REF TO if_wd_context_element,
           lv_index                     TYPE i.
    *--Get selected element
      lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
    ****Here itself its throughing dump because lr_element is initial***************
    *--get selected element index.
      lv_index = lr_element->get_index( ).
    can any one help me what is the wrong.. else suggest me how to get the selected elements from a table....
    Thanks in advance.

    *--Get selected element
    lr_element = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
    if  lr_element is bound.
    lv_index = lr_element->get_index( ).
    endif.
    Instead you can directly read the node if that row is a lead selected one.
    lo_node = wd_context->get_child_node( name = 'EMP' ).  "Emp is node name
    lo_ele = lo_node->get_lead_selection( ).
    or
    lv_index = lo_node->get_lead_selection_index( ).
    where is the above code written..is it written in OnLeadSelect event of the TABLE..
    can any one help me what is the wrong.. else suggest me how to get the selected elements from a table....
    As the selection mode is Auto there is no multiple selection..hence try to use the lead selection only.
    Edited by: Lekha on Jan 3, 2012 6:47 PM

  • How can I access the selected element of a DropDownByIndex-box?

    Hi,
    I want to create a WebDynpro with two web services. I created the first request with the first web service and the results are displayed in a DropDownByIndex-Box. Now the user should choose one of the results and I would like to use this for the request with my second web service. How can I access the selected Element of a DropDownByIndexBox in the Code?
    Thank you!!
    Julia

    Hi Julia,
    when user select one element in drop down it automatically set lead selection of node binded to dropdown.
    For example if you bind a dropdown to node myNode with value attribute myAttribute the lead selection of node myNode is set in the position of element choose from user.
    So to take this chooised element use this code:
    wdContext.currentMyNodeElement.getmyAttribute()
    bye
    Andrea

  • Firefox 33 HTML select elements do not display correctly

    HTML form <select> elements do not display options correctly in Firefox 33.
    For example:
    <select id="field_4" class="mainForm" name="field_4">
    <option value=""></option>
    <option value="submitted"></option>
    <option value="pending"></option>
    <option value="discarded"></option>
    <option value="all"></option>
    </select>
    should display a drop down with 5 elements (first one blank) but no elements at all are displayed.
    The bounding box does not seem to be computed correctly so no options display.
    I have observed this issue on multiple pages. These pages displayed correctly in older version of Firefox and they display correctly under IE. The problem occurs with no addons or additional themes installed. The problem does not occur in SafeMode so I suspect that it is theme related but the Default 33.0 theme is the only installed theme and it cannot be disabled outside of SafeMode. I tried installing and changing multiple themes without success. The problem persists after restarting Firefox and after rebooting the computer and even after uninstalling and re-installing Firefox.
    I can supply a screen shot if needed.

    You can try to disable hardware acceleration in Firefox.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    You need to close and restart Firefox after toggling this setting.
    *https://support.mozilla.org/kb/upgrade-graphics-drivers-use-hardware-acceleration
    If it works in Safe Mode and in normal mode with all extensions (Firefox/Tools > Add-ons > Extensions) disabled then try to find which extension is causing it by enabling one extension at a time until the problem reappears.
    Close and restart Firefox after each change via "Firefox > Exit" (Windows: Firefox/File > Exit; Mac: Firefox > Quit Firefox; Linux: Firefox/File > Quit)
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • When using the google translate js api to dynamically translate a webpage the chosen option in a select element does not show up. This happens to me only in FF (using v4)

    I am asking you this because I did not find this problem in any of the other browsers I have (chrome, opera, ie, safari).
    I uploaded a simple html file to show this problem here: http://rvyu.com/mKLG
    Notice that if you don’t change the language you have no problem changing the value in the select element (the original one with 3 options, not the one generated by google translate) but if you do when you switch values the selected one does not show up.

    Ok thank you so much, for your timely response.
    RESPONSES:
    1)   When I set up my iMac, I did not transfer any data directly from my windows PC.  I simply used the same iTunes login and account.  I have access to all of the files via the "Purchased" section of the iTunes store.  If I click "Download Previous Purchases"  text, I can download ALL of the purchases I have ever made.
    2)   I have the Apple TV 2, so good news, question answered.  I thought maybe it was the Apple TV 1, but it is the Black model, so bam.  Good response for you.  Well the whole damned reply is an awesome response, just pointing out that one piece of awesome.  I stated that it was an Apple TV 2, and yet you were still good enough to figure I could be mistaken, and provide me with knowleedge just incase.
    QUESTIONS:
    3)   So can my iMac not stream the data directly from itunes, without download?  Apple TV can, but perhaps that is something among many things that maker it unique, and awesome.
    SERIOUSLY.... THANK YOU... 
    I work in the computer support section for the Military.  The only problem is we use Windows , lol.  Well that and i've been gone for nearly 6 months on recover.  I go back next month though I hope.  But working in that field gives me the abilty to judge responses that run inside the same vein.  Your response was so awesome that I half thought I might have written it myself. 

  • Current selected element of table ( using tree  )

    Hi experts ,
                         I am using a tree by table UI in which master. I want to know text of current selected element of table (which is one of the column of table ) . as table is dynamically expanding or collapsing upon expanding or closing master column.
    so i used follwing code in do modify view to get it
    IWDTable tab =  (IWDTable) view.getElement("Table1");
                        tab.mappingOfOnLeadSelect().addSourceMapping("row", "element");     
    public void onActionOnrowSelect
    (com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int element )
        //@@begin onActionOnrowSelect(ServerEvent)
        //@@end
    but above code also give me current row (an integer value) .
    but its not solving my problem . as current row elemt is always not going to be same row in which table (data source for table).
    can any body have solution ?
    Regards
    abhay

    Hi Abay,
    IWDTable tab = (IWDTable) view.getElement("Table1");
    tab.mappingOfOnLeadSelect().addSourceMapping(IWDTreeNodeType.IWDOnLoadChildren.NODE_ELEMENT,"element");
    datatype of the <b>element</b> should be <b>IWDNodeElement</b>
    Or
    You can use
    IWDNodeElement IWDNode.getTreeSelection()
    Ex: wdContext.nodeA().getTreeSelection()
    Regards
    Ayyapparaj

  • Editor closes program when panorama is selected elements 7

    editor closes program when panorama selection of photos is selected, elements 7

    I have another question....
    I want to set my program to fill the screen. This works mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    but it covers the windows start bar. I want it to maximize and not cover the windows task bar (the thing that has the clock and start button etc...)
    also this program is intended for all plate forms. so for mac I don't want it to cover the task bar that is at the top of the screen.
    and for linux i don't want it to cover the task bar if there is one. thanks.

  • Sometimes Cannot Select Elements in Design view of Dreamweaver

    Hello,
    From time to time, i have trouble selecting elements in the design view.
    Sometimes it works right away. Sometimes I need to click 6-10 times, and sometimes it just doesn't work ( a larger all encompassing element stays selected and no matter how much i click, there is no change )
    I originally thought it was a bug, but I expected it to be fixed by now.
    This also seems arbitrary, perhaps someone here know why it's happening and how to avoid it.
    Thanks
    Peter

    You probably have a CSS overflow:hidden property applied to one or more divisions for float containment.  Switch to Split View.  Or turn off CSS styles in Design View:  View > Style Rendering > untick Display Styles.
    Or you can comment out /**overflow:hidden **/ until you're ready to Preview.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

  • Type choices in select elements

    I have an order entry form that uses a select list as the id
    that will be inserted into another table.
    I want the user to be able to type in several characters to
    locate an exact name or id in a table. Currently, the user can only
    type in one character to find a match on the first character in the
    select element. Do I have to write a function to accomplish this? I
    don't see any reference to cfselect and onKeyDown on this forum.
    So, I thought I'd ask before I go and recreate the wheel.
    Thanks,

    I would like to use the combobox-multicharacter search
    dropdown script but I am having trouble adapting your code to my
    database query/insert. I have changed the names to reference my
    form and query but it doesn't seem that the javascript is being
    invoked.
    I get no errors.....just the same functionality that is
    inherent with the browser. Should I do something else to
    this?

  • Scroll to Selection

    Is there a way to scroll to the currently selected image in the image browser?
    Moving between albums and changes to filters reset the browser's focus and often scroll the selected image off the screen.

    Yes, it's annoying, isn't it? I find what I do is just hit the left arrow key and then the right; that leaves me with the same image selected, but now it's scrolled up where I can see it. Of course, this doesn't work if you've been doing something that changes the keyboard focus.

  • Select element not found

    Hi,
     i am using vugen 11.00 for recording an application.. It is recording correctly but while replaying the script it is showing error as " SELECT element not found in the list"... The version of IE is 8.. is it application bug or vugen recording problem?
    please tell me how to resolve the bug... we are using Web( CLICK & SCRIPT) protocol..
     The error is occring in the below code line which is made bold ( web_list ).
        web_list("wddlOccurBeat",
            "Snapshot=t18.inf",
            DESCRIPTION,
            "Name=wddlOccurBeat",
            ACTION,
            "Select=BEAT 3",
            LAST);
        web_list("wddlOccurVillage",
            "Snapshot=t19.inf",
            DESCRIPTION,
            "class=sSfocus"
            "Name=wddlOccurVillage",
            ACTION,
            "Select=GOWDAKARANAGANAHATTI",
            LAST);
    Thanks,
    shrinivas

    I'm using another keyboard model (not vim-like). I often prefer to navigate with [shift]+[arrows] with [tab] in case of form. So this browsers are not suitable for me because it is not acting in a way that I like.

  • SELECT-ELEMENT

    hi!
    I have a SELECT element in my html-file and i can't get the selected value from it in NETSCAPE. In Explorer
    everything goes fine with the code tha is beneath.
    I am a very beginner in this and do not know if there is a error in my code or should i code this diffrently in NETSCAPE.
    Can anyone help me?
    Here is part of the code i have.
    function initSearch()
    var f = document.search;
    var fa = document.add;
    fa.ADD_FORM.options.length = 1;
    fa.ADD_FORM.options[1] = new Option('--Lakis��teinen tapaturmavakuutus', ' ');
    fa.ADD_FORM.options[2] = new Option(' Palkkatiedot 4 viikon ajalta', '/redbox/servlet/com.sampo.redbox.servlet.FormServlet?ACTION=NEW&FORMVERSION=0&FORMNAME=OccuAcci4WeekPay');
    <form name="add">
    <TABLE name="add_table" border="0">
    <TR>
    <TD> </TD>
         <TR>      
    <TD><FONT color=#000000 face=arial,helvetica size=3>Lomakkeet:</FONT></TD>
    <TD colspan=3>
         <SELECT NAME="ADD_FORM"     
    <option value="--none--">-
    <option value="--none--">Valitse Lomake . . . . . .
    <option value="--none--">-
    <option value="--none--">-
    <option value="--none--">-
    </SELECT></TD>
         </TR>
    <TR>
    <TD colspan=4 align="center">
         <input type="button" value="Avaa" onClick= "loadFormLink(document.add.ADD_FORM.value)">
    </TD>
    </TR>
         </TABLE>
    </form>

    This should do:
    document.yourForm.yourSelect[document.yourForm.yourSelect.selectedIndex].text;
    or
    document.yourForm.yourSelect[document.yourForm.yourSelect.selectedIndex].value;
    For more information here you have a link to the JavaScript reference.
    http://developer.netscape.com/docs/manuals/communicator/jsref/index.htm

  • [svn] 3733: Better scrolling and selection synchronization in List.

    Revision: 3733
    Author: [email protected]
    Date: 2008-10-17 16:32:38 -0700 (Fri, 17 Oct 2008)
    Log Message:
    Better scrolling and selection synchronization in List. Its not perfect, but better then what we had - though not where Halo List is. This is feature work to be done post-MAX.
    Reviewer: Glenn
    Checkintests: Pass
    QA: Yes
    Bug: SDK-17355
    Ticket Links:
    http://bugs.adobe.com/jira/browse/SDK-17355
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/components/FxList.as

    i had the problems and searched the WHOLE EARTH CATALOG   and didnt found the answer. but i have found it.
    i had changed the appletv video settings to output in 1080p 50hz. if you change it back to 1080p 60hz, then you will have smooth scrolling, and the press and hold effekt and reordering the apps on the homescreen will work again.

  • Shift-scroll not selecting multiple messages

    I've got two questions, but I'll post them separately to keep the threads clean...
    I just got a Curve 8330 (used to have an 8830 World Edition, with Sprint in case it matters) and I'm loving it so far. But for some reason, I can't click the SHIFT key and scroll to select multiple messages like I could on the other BB. I've tried about every combination I could think of: Left shift, right shift, alt, press and don't hold, press and hold, press both and hold, alt-shift and scroll. Nothing.
    Is it a software problem?
    Is there some weird "don't allow shift to be used for multiple selection" setting some place.
    Oh... and yes, the Shift key works just fine for other uses.
    Ideas?

    Hi and welcome to the forums,
    I have an Verizon 8330. You should be able to use either the right or left keys to press and scroll.
    Not to be insulting, but to verify,  the keys are located on the bottom row last key on each side of the keyboard.
    They have an up arrow in silver along with an aA in each. You should be able to highlight the message to start, press either shift key, and scroll the trackball to the last selected item. 
    I was just verifying the procedure.
    Has this not worked since you got it, or has it just started?
    Please let me know,
    Thanks
    Message Edited by Bifocals on 08-30-2008 04:15 AM
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

Maybe you are looking for