Reputation: 154
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?
Upvotes: 0
Views: 1044
Reputation: 324118
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.
Upvotes: 3