File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes ensureIndexIsVisible() - Please Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ensureIndexIsVisible() - Please Help" Watch "ensureIndexIsVisible() - Please Help" New topic

ensureIndexIsVisible() - Please Help

Rajesh Radh
Ranch Hand

Joined: Mar 18, 2001
Posts: 35
I am trying to display the desired month using ensureIndexIsVisible() method from a JList. But my JList always displays the value at index 0. Could you please let me know how could I use ensureIndexIsVisble(int) method working for me?

Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Rajesh,
IMO, the ensureIndexIsVisible method is only supported for JViewport object. Try chaning your ScrollPane to a Viewport and see if that works.
Rajesh Radh
Ranch Hand

Joined: Mar 18, 2001
Posts: 35
thanks for your reply.
My understanding is that JList uses Viewport view of JScrollPane for its scrolling purpose. I did not understand your quote "try changing JScrollPane to JViewport...". JViewport has only one constructor?
As per Java API,
"JList doesn't support scrolling directly. To create a scrolling list you make the JList the viewport view of a JScrollPane, e.g.
JScrollPane scrollPane = new JScrollPane(dataList);
// Or in two steps:
JScrollPane scrollPane = new JScrollPane();
By several trail and error, I found out that ensureIndexIsvisible(int index) works only when invoked from within a listener method! In order to get the result I had to put this method in windowOpened() method that is attached to a JFrame that holds my MonthRoll component. But the component I am developing is not supposed to be attached to a JFrame but only to a JPanel. Therefore I need to figure out how can I make ensureIndexIsVisible() working outside of a listener method!

[This message has been edited by Rajesh Radh (edited May 28, 2001).]
I agree. Here's the link:
subject: ensureIndexIsVisible() - Please Help
It's not a secret anymore!