ListCellRenderer problems
Hi,
I got a problem with a ListCellRenderer. I want to fill the listentrys with JPanels. The JPanels got a paintComponent-method with a gradientpaint, so i want make rows with a gradient.
But the renderer paints only the first row correct. The others without the gradient. Any help?
Message was edited by: Olek
Olek
[346 byte] By [
Oleka] at [2007-11-27 3:34:09]

# 2
i give u a snipped of the code, hope it will enough to understand :
// The class who should render the JList
class WeekMonthListRenderer
extends DefaultListCellRenderer {
// JLists are stored in a JTable
private JTable parentTable;
// List-entrys should get a backgroundcolor stored in a hashtable
private Color backGrndCol;
// The informations for the enty are stored in a String-Array
private String[] entry;
WeekMonthListRenderer(JTable parentTable) {
this.parentTable = parentTable;
}
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected,
boolean cellHasFocus) {
entry = (String[]) value;
// ignore this
if (entry[CLOCK] != "-1") {
backGrndCol = backGrnd.get(entry[TYPE]);
// ignore this
if (backGrndCol != null && backGrndCol.equals(Color.white)) {
backGrndCol = null;
}
// create new JPanel with gradient paint
Entry e = new Entry(backGrndCol);
// ignore this
String entryText = entry[START_HOUR] + ":" +
u.getCorrectClockMinuteValue(Integer.parseInt(entry[START_MINUTE])) +
"Uhr : " + entry[TITLE];
// add a JLabel to the panel
e.add(new JLabel(entryText));
return e;
// more code but ignore it
.
.
.
// class who should paint the gradient and antialiase the text
// both doesn't work correct
class Entry
extends JPanel {
private Color color;
Entry(Color color) {
this.color = color;
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
//System.out.println(color);
if (color != null) {
g2.setPaint(new GradientPaint(0.F, 0.F,
color,
this.getWidth(),
0.F, Color.WHITE));
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Rectangle r = this.getBounds();
g2.fill(r);
}
}
}
Oleka at 2007-7-12 8:37:17 >

# 3
Once again a description:
I put JLists in a JTable.
The JTable got an own Renderer who returns (JComponent)value to draw the JLists for itself.
The JLists got an own Renderer(DefaultListCellRenderer) who returned a JLabel if no entrys in the JList or a JPanel with GradientPaint
if there is a entry in the JList(add a JLabel with the entry-text to the JPanel).
It all works but the GradientPaint only works in each first row of the JList.
In the 2nd and all other the JList-row paints the JPanel with the JLabel but without the GradientPaint.
Hope it will now a little bit clear.
Oleka at 2007-7-12 8:37:17 >
