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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JList with variable row height

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
...
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
    Bookmark Topic Watch Topic
  • New Topic