简体   繁体   中英

jList disable auto resize

I'm using Netbeans graphical JFrame design. So I have a jList inside a jScrollPane (from the designer) and during the program I add some long strings (file paths) to the list.

Some strings are too long to fit in the list's width so the jList expands horizontally to fit the longest item. However, I want the width to be fixed and have a horizontal scrollbar at the bottom.

How can I do this?

You can use:

JList list = new JList(...);
list.setPrototypeCellValue("XXXXXXXXXXXXXXXXXXXX");
JScrollPane scrollPane = new JScrollPane( list );
panel.add( scrollPane );

to control the preferred width. The scrollbar will appear as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM