Aug 20

There’s a method in JComponent called scrollRectToVisible() which interacts with the parent scroll pane (if one exists) to change its viewport. It takes a Rectangle as an argument that specifies the area you want to be visible in the viewport.

So for example to scroll to a given row in a JTable you would use something like this:

table.scrollRectToVisible(
   new Rectangle(
      0, row * table.getRowHeight(),
      table.getWidth(), table.getRowHeight()));

written by objects \\ tags: ,

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: ,