Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with autoscroll a JList?

843806Jun 25 2008 — edited Jun 25 2008
Hi :)

I want to disable autoscrolling of my JList. So that when the user selects an item in the list, and moves the cursor outside the window, while still holding the button pressed, the list shouldn't scroll. I use the setAutoscrolls(false) method but with no success. Any help is much appreciated. Here is the code:
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class Main {

	private static final String[] ITEMS = new String[] {"1",
		"2","3","4","5","6","7","8","9","10","11",
		"12","13","14","15","16","17","18","19","20","21",
		"22","23","24","25","26","27","28","29","30"};
	
	public static void main(String[] args) {
		JFrame f = new JFrame();	
		JList list = new JList(ITEMS);
		list.setAutoscrolls(false);
		JScrollPane scrollPane = new JScrollPane(list);
		f.add(scrollPane);
		f.setPreferredSize(new Dimension(200, 200));
		f.pack();
		f.setVisible(true);
	}
}
Kind regards,
/Patrik
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2008
Added on Jun 25 2008
9 comments
385 views