JLIST - Scrollpane woes

K

Kurt M Peters

I am having a problem getting a JList to scroll.
I am using an extension of AbstractListModel at a model in a JList:
public class TreeSetListModel extends AbstractListModel {
private Set<String> treeSetList;
/** Creates a new instance of TreeSetListModel */
public TreeSetListModel(Set<String> inSet) {
treeSetList = inSet;
}
....
}

For the life of me, I cannot get the vertical scrollbar to scroll. The
horizontal one does (which actually is useless). Does anyone have any ideas
what I'm going wrong? Please see comments and code handling the guilty
objects below:

jSPListNodes = new JScrollPane(JListNodes);
JListNodes = new javax.swing.JList();

jSPListNodes = new JScrollPane(JListNodes);
jSPListNodes.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jSPListNodes.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jSPListNodes.setAutoscrolls(true);
jSPListNodes.setMaximumSize(new java.awt.Dimension(48, 48));
jSPListNodes.setPreferredSize(new java.awt.Dimension(48, 48));
jSPListNodes.setViewportView(JListNodes);

jPNodeComponentSelections.add(jSPListNodes,
java.awt.BorderLayout.WEST);
JListNodes.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
JListNodes.setFixedCellHeight(48);
JListNodes.setMaximumSize(new java.awt.Dimension(264, 264));
JListNodes.setMinimumSize(new java.awt.Dimension(52, 70));
JListNodes.setPreferredSize(new java.awt.Dimension(52, 80));
JListNodes.setVisibleRowCount(2);
// after creating and filling a TreeSet, I put it in the List
JListNodes.setModel(new TreeSetListModel(nodeSet));
//I even tried to revalidate, which doesn't seem to work:

JListNodes.revalidate();
jPNodeComponentSelections.revalidate();
jSPListNodes.revalidate();

Thanks in advance,
Kurt
 
A

Andrey Kuznetsov

JListNodes.setMaximumSize(new java.awt.Dimension(264, 264));
JListNodes.setMinimumSize(new java.awt.Dimension(52, 70));
JListNodes.setPreferredSize(new java.awt.Dimension(52, 80));

don't set preferredSize.
 
A

Andrey Kuznetsov

JListNodes.setPreferredSize(new java.awt.Dimension(52, 80));
Could someone please explain why not?

because preferred size is used by JScrollPane's (or may be JVievport's)
LayoutManager.
If preferred size set explicitly, then JList's size is no more changed
according to its requrements.
 
K

Kurt M Peters

Thanks, I will give it a try. I probably will have to do some special
"manuevering" with Netbeans to NOT set prefered size. Does anyone have any
hints on how to reset prefered size to "not be set" in Netbeans?

Regards,
Kurt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top