Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2004

Tip: Looking for answers? Try searching our database.

JList scrolling

Thread view: 
Adam - 06 Feb 2004 13:08 GMT
Hi

I have a JList contained within a JScrollpane container and am using the
following code to ensure the last item in the list is always visible.

DefaultListModel  model = new DefaultListModel();
JList list = new JList(model);
JScrollpane pane = new JScrollPane(list);
getContentPane().add(pane);

list.ensureIndexIsVisibile(model.size()-1);

This does not seem to work, there does not seem to be a pattern to wether
the last item is displayed or not.

Can anybody help?

Thanks
Adam
Kleopatra - 06 Feb 2004 14:28 GMT
> Hi
>
[quoted text clipped - 7 lines]
>
> list.ensureIndexIsVisibile(model.size()-1);

when exactly are you doing this? If on start-up of your program, make
sure to call the ensure... after the frame is realized (that is after
pack() or setSize()) or wrap the call into a
SwingUtilities.invokeLater(). If you want it after an item is added to
the model, invoke as well - that will ensure that the list has completed
the update of its internal state.

Greetings
Jeanette
Adam - 11 Feb 2004 11:21 GMT
i am adding/removing items to the list dynamically at run time when the user
clicks a button.
i want the last item added to be displayed after it is added.

> > Hi
> >
[quoted text clipped - 17 lines]
> Greetings
> Jeanette


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.