JList problem with row height

Hi there,

I've got jList declared by DefaultListModel. It is inside a jScrollPane. The problem is, that sometimes it creates list with for example two objects inside, but one of the rows showed in list is stretched to many lines (for example it is like 15 lines high, but there's still only one line long String in the middle of the 15 lines).

Here's some code:

private JPanel jContentPane =null;

private JScrollPane jScrollPaneSubunits =null;

private JList jList =null;

private DefaultListModel dlModel =new DefaultListModel();

private JPanel getJContentPane(){

if (jContentPane ==null){

jContentPane =new JPanel();

jContentPane.setLayout(null);

jContentPane.add(getJScrollPane(),null);

}

return jContentPane;

}

private JScrollPane getJScrollPane(){

if (jScrollPane ==null){

jScrollPane =new JScrollPane();

jScrollPane.setBorder(javax.swing.BorderFactory

.createTitledBorder(null,"List:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,

javax.swing.border.TitledBorder.DEFAULT_POSITION, null,null));

jScrollPane.setLocation(new java.awt.Point(15,315));

jScrollPane.setSize(new java.awt.Dimension(211,140));

jScrollPane.setViewportView(getJList());

}

return jScrollPane;

}

private JList getJList(){

if (jList ==null){

jList =new JList(dlModel);

}

refreshList();

return jList;

}

privatevoid refreshList(){

dlModel.clear();

for (int i = 0; i < 10; i++){

dlModel.addElement("X " + i);

}

}

Any ideas what's wrong?

[3227 byte] By [Anganiela] at [2007-11-26 22:31:27]
# 1
Works fine for me.If you want further help post a Short, Self Contained, Compilable and Executable, Example Program ([url http://homepage1.nifty.com/algafield/sscce.html]SSCCE[/url]) that demonstrates the problem.
Rodney_McKaya at 2007-7-10 11:37:01 > top of Java-index,Desktop,Core GUI APIs...
# 2
have you tried using Component.setMinimumSize(....), Component.setPreferredSize(...), Component.setMaximumSize(....), ...in the component returned bei your model?
jEti182a at 2007-7-10 11:37:01 > top of Java-index,Desktop,Core GUI APIs...
# 3
You could try calling either jScrollPane.getViewport().setViewSize(dimension) or jlist.setPreferredSize(dimension) where Dimension dimension = new java.awt.Dimension(211,140).
smalinowa at 2007-7-10 11:37:01 > top of Java-index,Desktop,Core GUI APIs...
# 4
I would suggest stopping the bad practice of nulling the layout manager. It may or may not affect this specific issue, but stop doing it anyway.
itchyscratchya at 2007-7-10 11:37:01 > top of Java-index,Desktop,Core GUI APIs...