JScrollPane not showing in JList

listModel =new DefaultListModel();

jList2 =new JList(listModel);

scrollPane =new JScrollPane(jList2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

The above still doesn't show the scrollPane. Any suggestions why?

[374 byte] By [iPortala] at [2007-11-27 2:44:31]
# 1
could be the layoutManager you're usingtry adding this linescrollPane.setPreferredSize(new Dimension(100,100));
Michael_Dunna at 2007-7-12 3:11:11 > top of Java-index,Java Essentials,New To Java...
# 2
Tried it, but didn't work.As for my layout manager, i'm not using one (well in JBuilder, you can choose a "null layout").
iPortala at 2007-7-12 3:11:11 > top of Java-index,Java Essentials,New To Java...
# 3

works OK in this, using a null layout

import javax.swing.*;

import java.awt.*;

class Testing

{

public void buildGUI()

{

DefaultListModel lm = new DefaultListModel();

final JList list = new JList(lm);

JScrollPane sp = new JScrollPane(list,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,

JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

for(int x = 0; x < 100; x++) lm.addElement(""+x);

sp.setBounds(0,0,392,366);

JFrame f = new JFrame();

f.getContentPane().setLayout(null);

f.getContentPane().add(sp);

f.setSize(400,400);

f.setLocationRelativeTo(null);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

}

public static void main(String[] args)

{

SwingUtilities.invokeLater(new Runnable(){

public void run(){

new Testing().buildGUI();

}

});

}

}

Michael_Dunna at 2007-7-12 3:11:11 > top of Java-index,Java Essentials,New To Java...