Re: Paint a stickman in a JTable cell



Sven-Ivar Fjeld <sven-ivar@xxxxxxxxx> wrote:
> So, specific questions are:
>
> 1. Is it easy to draw polygons, arcs and circles in a cell in a table,
> possibly by using an overriding paint(Graphics g) method? A simple yes
> or no would do as I would quite enjoy the challenge of figuring it out.
> At the moment I am thinking something along these lines, where JEntity
> is a JLabel with it's own overriding paint method:
> public class EntityTableCellRenderer extends JEntity implements
> TableCellRenderer { // Normal code stuff goes here }
> .

Yes, that works just fine.

> 2. Is it easy to implement cells that can hold objects? Say, if an
> earthquake hit an area, i.e. a cell, can the cell trigger some event
> that is propagated to objects? Could an Observer pattern be used here,
> so the objects observe the cell, or are there better ways of
> notification? Any hints would be great.

Yes, table cell values can be any arbitrary object. The cell renderer
just needs to be able to understand the object and provide an
appropriate visual representation. If you use the default renderer,
then that means the object should override toString... but if you plan
to install your stick figure renderer, then even that requirement is
gone.

> 3. Can a JPanel be easily added to a cell?
>

No, but you can return a JPanel instance from a cell renderer.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.