Only scroll to JList cell if required

Hi all.
I have a JList in a JScrollPane. I would like the the selected cell to be visible but the method list.ensureIndexIsVisible(index); doesn't do quite what I want.
The behaviour I would like is that if the cell is already visible don't scroll at all. If the cell isn't visible, scroll so that it is the last cell selected.
The code below demonstrates the problem. With index set to 3, I get the behaviour I want, however, if I set the index to 10, I can't see the selected index.
If I enable the ensureIndexIsVisible method, the selected cell is always shown at the top of the list, or as far towards the top as possible.
thanks..
import javax.swing.*;
public class JListTest extends JFrame {
    public JListTest() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JList list = new JList(new String[] {"BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla", "BlaBlaBla"});
        JScrollPane scrollPane = new JScrollPane(list);
        add(scrollPane);
        int index = 3;
        list.setSelectedIndex(index);
//        list.ensureIndexIsVisible(index);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new JListTest();
}

I actually thought this was the default behaviour.
If you change your code to:
        int index = 3;
        list.setSelectedIndex(index);
//        list.ensureIndexIsVisible(index);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
        list.ensureIndexIsVisible(index);then I believe it works the way you want. So I guess the problem is that the components haven't yet been realized when you invoke the method call which is causing the scrolling for some (unknown) reason.
It also works if you wrap the method call in a SwingUtilities.invokeLater().

Similar Messages

  • IOS5.0.1 constant error "iPhone can not make or receive calls.  Restore from iTunes":  I get this message and the phone will no longer work (happend once while on airplain mode and now once while in wifi only area, out of cell range).  help!

    All- I get this message ("iPhone can not make or receive calls. Restore from iTunes" (happend once while on airplain mode and now once while in wifi only area, out of cell range)). iPhone 4.  Newest OS.  Never happened with old OS! Cycling phone on/off does not help.  Ignoring message causes phone to cycle off then on.  After first time this happened, I restored.  Six days later...same problem!  Clearly a new fix is necessary.  Suggestions? 

    I have not tried that...I will look up the process so that I can do it correctly (and still transfer all of my files, contacts, etc).  Any suggestions?  What is the advantage of restoring as a new device..is this more akin to a complete wipe of a hard drive?

  • Why does my mouse wheel only scroll up in the catalog.  It works correctly in every other program.

    When in a catalog folder and showing a single picture, the mouse wheel only scrolls up, not down.  This behavior is not seen in any program other than elements.  If more than one line of pictures is showing in the window, it works fine, both up and down scrolling.

    Hi All,
    Please refer to the following article and do the needful:
    Photoshop Elements Help | Photoshop Elements hotfix 13.1.1
    It should solve the scrolling issue.
    Thanks,
    Anwesha

  • How to include a panel in a jlist cell

    i have used the jlistcellrenderer and returning the panel there in the getcellrendererComponent mathod .. its working ... but when i am adding one label to that panel , then it should come like ..... in one cell, one panel, and in that one label ... but i am finding many labels in one jlist cell ... it shows like that ..
    can anyone help ????
    if anyone have a sample example then plz send it ...

    You could subclass JTable and override getCellRenderer
    -Puce

  • Nokia 6600 only works from one cell tower

    I have this weird problem with my phone where it will only work off one cell tower. Once I leave the coverage of that cell tower it will not work anywhere else.
    It started a few months ago and i'm not to sure why?
    The funny thing is it's the cell tower on top of my building at work, so when i'm at work it will work (calls/txt/etc) but as soon as I go home or even go to another city it will not.
    Any ideas?

    The first thing I'd recommend you do is to reset your phone, but I can't tell from the 6600's webpage what OS you're running so I can't give you instructions on how to do this.
    Have a look through your menus to see if you can find an option to reset to factory defaults, but please remember that doing so will wipe ALL data from your phone.
    If you wish to backup your data you can do so using the PC Suite application which you can find here :
    http://www.nokia.com/pcsuite
    Hope this helps.
    Regards,
    Edward

  • Mighty Mouse (wireless) will only scroll up & not down

    Has anyone come across an issue like this, I think it is hardware, but thought I would ask around first?
    I tried using our 2nd wireless mighty mouse that is paired with the iMac and that worked correctly (scroll both up and down) when paired with my MacBook Pro. However, when I re-paired the mouse in question, it still only scrolls up.
    Any thoughts are greatly appreciated.
    Thank you

    Hi bbwc-
    Greetings and welcome to the Apple boards
    You must clean said mouse: How to clean your Mighty Mouse
    Luck-
    -DaddyPaycheck

  • My mouse will only scroll one way

    My mouse will only scroll down and not up, it has done this before and self cured after a few days. any suggestions?

    I assume you are referring to a mouse with the scroll button/wheel in the middle?
    I have seen this a few times with more than one such mouse. I have "cured" it by putting some pressure (e.g. considerably more than normal) downward on that scroll wheel and moving it in the direction that it is no longer moving in (e.g. scrolls only down but not up, or vice versa). By applying a fair amount of pressure (don't break it but it's much more pressure than normal for a short time), it seems to suddenly "catch" and then works fine.

  • The scroll motion where I set the fill is only scrolling down

    The scroll motion where I set the fill is only scrolling down, even when I set it to go up. Has anyone else expereinced this? Can you help me correct this?

    Hi Crystal,
    Could you please explain in details what you have done so that I can test it out at my end? Is there a live page where I can check the issue? Can you create a trial site on BC and then show it to me so that I can investigate the issue further? Thanks.
    - Abhishek Maurya

  • HT4059 My IOS is 4.1, iphone 4. Where can I get ibooks-1? In itunes only ibooks 3 is available which requires ios6+.

    My IOS is 4.1, iphone 4. Where can I get ibooks-1? Even ibooks 2 is also unavailable.
    It they are now out of support, then is there any other application that I can use for pdf books reading? I only want to download books from itunes or my collection and to read them over my iphone.
    In itunes only ibooks 3 is available which requires ios6+.
    Please advice.
    Thanks & Regards,
    Muhaimin

    Only the current version of each app is available for download from the store, so for iBooks there is only the version that requires iOS 5+
    There are other apps in the store which support PDFs, though I don't how many work on iOS 4.1 - 'PDF Manager Free' appears to be one, and the Stanza app also says that it supports PDFs

  • Bookmarks only scrolls down to a certain point and can't add any?

    Had a multiple virus attack and have most everything fairly well back to function and restoration. But in the process Bookmarks stopped functioning properly. I'm unable to add, only scrolls down to a certain point and I've gone through the Restore steps multiple times without success. HELP.

    What are the yellow warning signs, maybe a screenshot would help.
    * [[How to make screenshots]]
    * [[How do I create a screenshot of my problem?]]
    If you disconnect from the internet you will get warnings and they may include yellow triangles.
    Are you using the problem laptop again now or are you using something the cat has not been sleeping on ?
    From what you say it seems Firefox is working ok but some tabs still will not work

  • Apple Mouse only scrolls in one direction after 10.6.8 update

    I just updated to 10.6.8 security update, itunes and safari update (I think?) Can't remember now. The update was 10-4-11.
    My Apple mouse now only scrolls in one direction. I thought is was dirty and it is not. There are posted issues with this safarie update with mouse related problems, however I am experiencing them in all programs.
    Rebooted several times, re-cleaned mouse scroll ball, did the paper trick by cleaning. No success.
    I can scroll down but not up. It forces me to grab the scroll bar and manually drag the scrolling window.
    Again ALL programs. Was just fine right before the update. Now a problem after
    Ben

    swb gives good advice. If that didn't work:
    How to really clean your Mighty Mouse (with caution!):
    http://support.apple.com/kb/HT3226?viewlocale=en_US
    and:
    http://web.mac.com/karelgil/iWeb/MacWebSite/MightyMEng.html
    http://www.linklink.co.uk/apple-computers/cleaning-inside-and-dismantling-the-ap ple-mighty-mouse/

  • How can I get trial for after effects 4? it is the only version my PC meets the requirements.

    How can I get trial for after effects 4?
    it is the only version my PC meets the requirements.

    Hello  yaniv7m,
    in my eyes you will find it only in shops like ebay or Amazon, like this:
    http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0.Xafter+ef fects+4&_nkw=after+effects+4&_sacat=0
    or
    http://www.amazon.com/Adobe-After-Effects-CS4-VERSION/dp/B001EUJ0SI/ref=sr_1_1?s=software& ie=UTF8&qid=1407396391&sr=1-1&keywords=after+effects+cs4
    Good luck!
    Hans-Günter

  • How to make OO ALV Grid cell is required on data_changed?

    Hi all,
    I want to make grid cell is required on data_change method. I have two fields dependent each other, so i insert a value on a field, the other field should be obligatory.
    I have tried to solve this with "add_protocol_entry" method. But i don't want to display message log. The second field should be drawn with red border.
    My sample code is below:
    LOOP AT p_data_changed->mt_good_cells INTO ls_good_cells.
         CASE ls_good_cells-fieldname.
           WHEN 'FIELD1' .
             CASE p_sender.
               WHEN g_grid.
                 CALL METHOD p_data_changed->get_cell_value
                   EXPORTING
                     i_row_id    = ls_good_cells-row_id
                     i_fieldname = ls_good_cells-fieldname
                   IMPORTING
                     e_value     = lv_variable.
    *-- On this area the second field should be drawn with red border.
             ENDCASE.
         ENDCASE.
       ENDLOOP.
    I'm waiting for your helps.

    Gutten Tag,
    I have an idea, how about that you add one more field in your table structure for obtain information about color about each cell.  such as "color TYPE lvc_t_scol " and then in your lvc_s_layo, you should fill CTAB_FNAME = 'COLOR'.
    Insert this code into your program. (it's a template)
    READ TABLE itab WITH KEY <k1> = ..... ASSIGNING <fs>.
    APPEND INITIAL LINE TO <fs>-COLOR ASSIGNING <fs_l>.
          <fs_l>-fname = 'XXX' .   "字段名
          <fs_l>-color-col = 6.
          <fs_l>-color-int = 1.
          <fs_l>-color-inv = 0 .

  • My Apple wireless mouse only scrolls one way.  I've tried cleaning the

    My Apple wireless mouse only scrolls one way.  Any ideas on how I can set it up so it scrools up and down?

    I am having the same problem also.  I've tried cleaning the ball, but still not working.  This happened a couple of times before....and by accident I hit some button and it started working again.  So frustrating........sorry I'm not any help. Just venting.

  • Scroll Up only scrolls two thirds of my text

    Using livetype 2.1.3 to generate some scrolling credits. I used the Scroll Up effect and pasted in 94 lines of text (originally in FCP6 which scrolls it very badly). My text track is in the middle of the screen and it only scrolls about two-thrids of the text and then stops. I have tried altering nearly everything about my text and nothing alters this issue.
    Anyone know where I'm going wrong or an easier way to scroll this amount of text?
    TIA
    Kevin

    Hi Kevin
    I've been producing scrolling credits for quite a while which look absolutely stunning - in fact better than I ever expected. I'm a bit of a perfectionist, but the results I have achieved from LiveType are perfect.
    I am working in SD PAL (25 fps) widescreen (16:9).
    Afiter playing around with Livetype, I had a few disappointments, but the trick is, I think, to experiment - with speeds, fonts, durations, etc.
    The details of my last scroll are: 12 lines of text with several breaks in between, total duration 24.04 seconds.Font & size: Impact 35 pt - white text on black background.Speed 5.9%
    The only extra I did was to apply the filter "Shift Fields" (because of a flaw with PAL fields between Livetype and FCP).Otherwise my title would have been jittery and unusable.
    I will admit the Livetype documentation is poor, and IMHO is best ignored or used with extreme care.
    The Larry Jordan tutorial referred to I found of no help at all.
    You may have to break your 94 lines of text (font? size? duration?) into 2 or 3 separate scrolls and dissolve them in FCP.
    Regards
    Robert

Maybe you are looking for

  • HP Network Printer Wizard refuses to launch in Vista Ultimate (64 Bit Edition)

    HI, I have just installed the latest version of the HP Network Printer Wizard v8.1 but it refuses to run.  The is no error as such but the software just fails to launch? I have tried setting to windows XP compatibility mode to try to get it to run bu

  • Indesign CS3 error on start up

    Indesign CS3 on startup up reports a Java Script error- number 45 line 387. Had previously been working fine. Also works ok in other user accounts on my mac. I have tried trashing preferences, renaming recovery data, using clean up tool and then re-i

  • CONVERT_ABAPSPOOLJOB_2_PDF (font size)

    Hi. I am using function module <b>CONVERT_ABAPSPOOLJOB_2_PDF</b> in my program to create PDFs. This works fine, but recently I believe some system settings have been changed as the <b>font size</b> in the generated PDF has <b>increased</b> (no change

  • Operating system Windows 7 Home Premium x64 download

    Hello, I have changed broken harddisk in my HP ProBook 4540s and I'm looking for Windows 7 Home Premium x64 (Czech). I have HP DVDs with this OS, but it doesn't boot. So I called to HP and then they sent me another DVD, but it doesn't work too. Where

  • Launching Photoshop Elements 12 Organizer

    Getting an error message when trying to launch Elements 12 Organizer on MacBook Pro 10.6.8.  Elements 12 Editor is working fine.