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?
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.
Joined: Mar 18, 2001
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).]