Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

JList with variable row height  RSS feed

 
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 ]
 
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.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
...
 
Bartender
Posts: 11445
18
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
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!