🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #13335

Custom TableCellRenderer problems

#13335
From: Tapio Holopainen
Date: Thu, 13 Aug 1998 00:00
46 lines
1685 bytes
I manage to write my own TableCellRenderer (implementing
TableCellRenderer interface).

It looks like that:

import com.sun.java.swing.table.*;
import com.sun.java.swing.*;

public class MyCellRenderer implements TableCellRenderer 
{
	private JLabel _label = new JLabel();
	
	public MyCellRenderer()
	{
		_label.setBackground(Color.lightGray);	
	}
	
	public void setCellIcon(ImageIcon icon)
	{
		_label.setIcon(icon);		
	}
	
	public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int column)
	{
		return (Component)_label;	
	}
}

I plug it in JTable's first column:

table.getColumnModel().getColumn(0).setCellRenderer(new
MyCellRenderer());

Idea is to change first columns background, but it won't change...
Renderer 'looks' like work: e.g if I put ImageIcon on JLabel, JTable
paints it to first column, but the background remains white (default).

Second problem is: how to make focusing work? Should I do some 'tricks'
when  getTableCellRendererComponent-method is called?`

If somebody could give some examples that would be nice.

Thanks in advance!

- Tapio
Technical Details
Message-ID: <35D2D8F2.51F5956F@sysline.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,57916e49c4da661f,start
X-Google-Attributes: gid111d45,public
From: Tapio Holopainen <tapio.holopainen@sysline.com>
Subject: Custom TableCellRenderer problems
Date: 1998/08/13
Message-ID: <35D2D8F2.51F5956F@sysline.com>
X-Deja-AN: 380725668
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Sysline Oy
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing