aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JList with variable row height Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply locked New topic
Author

JList with variable row height

S Dan
Greenhorn

Joined: Apr 05, 2005
Posts: 25
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Apr 05, 2005
Posts: 25
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Apr 05, 2005
Posts: 25
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Feb 11, 2010
Posts: 3
...
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10522
    
    9

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList with variable row height