Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
    Bookmark Topic Watch Topic
  • New Topic

JList with variable row height

 
S Dan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Report post to moderator
How can I implement a JList with varible row height? Can someone provide me a complete example code?
Thanks.
-Dan
[ July 08, 2005: Message edited by: S Dan ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Report post to moderator
if you mean variable between lists, look up
setFixedCellHeight()

if you mean variable between rows of a list, look up
DefaultListCellRenderer
where you override getListCellRendererComponent() to set the preferredSize
of the label, depending on the criteria of the row
 
S Dan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Report post to moderator
Doesn't work. I already tested that before posting the message. I've overridden
getListCellRendererComponent. I'm trying to change the height of a particular row when the cell is selected. So I'm trying to do this inside the getListCellRendererComponent method..
if(isCellSelected){
this.setPreferredSize(new Dimension((int)this.getSize().getWidth(),50));
this.validate();
}

No effect whatsover. Using setSize instead of setPreferredSize doesn't help either.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Report post to moderator
works OK if you reset the renderer in ListSelectionListener's valueChanged()
and in getListCellRendererComponent
if(list.getSelectedIndex() == index) lbl.setPreferredSize(new Dimension(100,75));
else lbl.setPreferredSize(new Dimension(100,20));
 
S Dan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks Michael. But could you please provide a complete working example? I'm still having some problems with this..
Thanks.
-Dan
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is the code I was suggesting - run it as is,
then change the commented bits around, which is a better way to do it.

 
mumbo alex
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
...
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Welcome to the Ranch.
I have edited out your post.
New questions should be asked in new threads.
http://faq.javaranch.com/java/UseOneThreadPerQuestion

You can post a question by using the button
 
    Bookmark Topic Watch Topic
  • New Topic