JList is not scrollable.

I am developing a tool for text mining. I use JList to hold all unique terms and their statistically significant values. I encounter a problem that when I create JList and put it into JScrollPane, the JScrollPane is not scrollable. I use Netbeans IDE 5.5.1 for my development that includes GUI design. JList and JScrollpane are instantiated in the GUI design step. A snippet on one of my classes for adding data into JList is below.

DefaultListModel model=new DefaultListModel();



String[] data={“hello”, “world”};



The problem that the Scrollpane is not scrollable is originated in my GUI design step when I set the preferredSize of the JList. The reason is that when the preferredSize of JList is manually set by developer, the size will no longer change although new items are added into the JList.

The solution to this problem is to not setting the preferredSize of the JList (removing the setting statement). In Netbeans IDE 5.5.1, unsetting the preferredSize of the JList can be achieved by right clicking on the preferredSize property of the JList and then selecting “restoring default value”.

In conclusion, set preferredSize of the JScrollPane only. Do not set the preferredSize of the JList.

This entry was posted in Java. Bookmark the permalink.

4 Responses to JList is not scrollable.

  1. Matt says:

    Good job, man. You solved my problem. Thanks a lot.

  2. rhenabeth says:

    Thanks for the tip. It answered my question too…

  3. NateWasHere!!! says:

    Wow!! I wrestled with this for 2 hours!!! LifeSaver!!!

  4. Hansonite says:

    That kept me busy for days, but your article solved my problem as well. Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s