Nov 15

You need to set the preferred size of the JScrollBar components.

scrollpane.getVerticalScrollBar().setPreferredSize(
   new Dimension(width, Integer.MAX_VALUE));
scrollpane.getHorizontalScrollBar().setPreferredSize(
   new Dimension(Integer.MAX_VALUE, width));

written by objects \\ tags: ,

Oct 29

You need to add your JList (or any component) to a JScrollPane. Easiest way to do this is to pass your component to the JScrollPane’s constructor. You then add the JScrollPane to your component hierarchy (instead of adding your JList).


JScrollPane scrollPne = new JScrollPane(mylist);
panel.add(scrollPane);

written by objects \\ tags: ,

Oct 01

The JViewport of the JScrollPane provides a method to return the location of top left point showing in the scroll pane.


JViewport viewport = myScrollPane.getViewport();
Point scrolledTo = viewport.getViewPosition();  

written by objects \\ tags: ,