wood burning stoves 2.0*
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
Author

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.
Regards,
Manfred.
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();
scrollPane.getViewport().setView(dataList);"
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: http://aspose.com/file-tools
 
subject: ensureIndexIsVisible() - Please Help