I am having problems with scrolling on a JScrollPane.
I have a list of images in a JList which I am placing on a JScrollPane. The list can be very long, sometimes hundreds or thousands of images. I add the JScrollPane to a JPanel, and the image gets drawn successfully, the JScrollPane adds scroll bars when needed and the scroll bars can move the image. The response from the scrollbars are good if the list of images is simple (10 - 20).
However, lists that run into the hundreds cause the vertical scrolling to initially run very slowly until all the images have been shown, then the scrolling speed returns to normal.
Can anyone suggest a technique to speed the initial scrolling response? I have experimented with adjusting the viewport settings (eg JViewport.BACKINGSTORE_SCROLL_MODE, JViewport.BLIT_SCROLL_MODE) but these did not lead to any improvement in the initial scrolling response.
The code that I am using is represented below.
prList = new JList(prListModel); // a list of interactive images for the JScrollPane
MouseAdapter listener = new PrChangeListener(prList, this);
prList.addMouseListener(listener);
prList.addMouseMotionListener(listener);
renderer = new PrRenderer();
renderer.setPreferredSize(getIconPreferredSize());
prList.setCellRenderer(renderer);
prList.setBackground(Color.WHITE);
prList.setSelectionBackground(new Color(225,225,225));
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
//try separate linked scroll bar for scale bar ...
prListModel scaleBarListModel = new prListModel();
scaleBarListModel.addElement(intArray[0]); // a scale bar to sit above the JScrollPane
scaleBarList = new JList(scaleBarListModel);
scaleBarList.setCellRenderer(renderer);
scaleBarList.setBackground(Color.WHITE);
scaleBarList.setSelectionBackground(Color.WHITE);
scaleBarScrollPane = new JScrollPane(scaleBarList,JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
prListModel.removeElementAt(0);
prScrollPane = new JScrollPane(prList);
prScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
prScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scaleBarScrollPane.getHorizontalScrollBar().setModel(prScrollPane.getHorizontalScrollBar().getModel());
JPanel twoPanePanel= new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.VERTICAL;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx=0;
gbc.gridy=0;
gbc.weightx=1;
gbc.weighty=0.1;
twoPanePanel.add(scaleBarScrollPane, gbc);
gbc.gridx=0;
gbc.gridy=1;
gbc.weighty=0.9;
twoPanePanel.add(prScrollPane,gbc);
add(twoPanePanel);