• Post Reply 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Different cell sizes for jlist cells

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a list which use a panel as the renderer. The height of the renderer panel is depends on the text in that panel. (See the Image-1)
But the problem is that all renderer panels becomes the size of the biggest panel.

I override the renderer panel's (NoticePanel) paintCopmonent() and draw the lines and the curve. This NoticePanel has a jtextarea and a label to accommodate the text. I create this panel inside the renderer's getListCellRendererComponent() method with the correct height and with. Actually i calculate the height depending on the text. I set that size in NoticePanel's preferredSize() in its initialize() method.

class NoticeCellRenderer extends DefaultListCellRenderer
{
private final CambioPanel panel = new CambioPanel();

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus)
{
// Calculate the height of the component and create the panel with that height.
NoticePanel noticePanel = new NoticePanel(value, height);
return noticePanel;
}
}

public class NoticePanel extends CambioPanel
{
private void initialize()
{
this.setPreferredSize(width,height);
}
}

But all the NoticePanel that are in the list has same height. First panel in the list (with a red color arrow) has a wrong size. It has taken the size of the other panel which has the correct height.

How can I get different sizes on different cells in this list?


Thanks.



Image-1.JPG
[Thumbnail for Image-1.JPG]
 
It's feeding time! Give me the food you were going to give to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic