🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Buttons in JTable

#8982
From: Thomas Denn
Date: Tue, 20 Jun 2000 00:00
45 lines
2647 bytes
Why don't you make that object your cell editor for that column.  The cell
renderer object could also be an object of that type, but as John explains,
the renderer object is just used as a "rubber stamp" on the graphics
context.  The same class can implement both TableCellRenderer and Editor
interfaces.
Tom

"John P. McGrath" wrote:

> On Fri, 16 Jun 2000 10:38:14 +0200, Andreas Schnell wrote:
>
> > I'd like to have some Buttons in front of each line of a
> > JTable. The Buttons are for editing or deleting the line.
> > I created a button renderer with the buttons, where each
> > of them has an ActionListener. The Button looks good, but
> > I couldn't get any event, when clicking on them.
>
> In order to understand what is happening, you have to understand how a
> JTable works.  A table can have a fairly large number of cells.  If the
> JTable created a separate component for each cell, that could take up
> quite a bit of resources.  A 100x100 table is not too unreasonable, and
> that would 10,000 cells, which would consume megabytes of memory.  So a
> JTable (and a JTree) does its painting using Cell Renderers.
>
> When a cell needs to be painted, it asks the cell renderer to provide it
> with a component to use to render the cell.  Then, it creates a graphics
> context that points to the cell position and asks the renderer component
> to paint itself on that graphics context.  In essence, it is virtually
> placing the component in the cell position for the duration of the paint
> operation.
>
> So you can see that adding a listener to a cell renderer component will
> not work, because the component is not in the cell.  If you click on the
> cell, the JTable will get the event, not the cell renderer component.
>
> But there are ways to accomplish what you want.  The following site has
> many examples of doing strange things with JTables, including "placing"
> buttons in cells.
>
>     http://www2.gol.com/users/tame/
>
> --
> John P. McGrath
> <JPMcGrath@fast.net>
> <jpm@nscs.fast.net>
Technical Details
Message-ID: <39502C7D.492E46DA@earthlink.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3949e5cb@dnews> <MPG.13b4ca55ff6c6cb39899d5@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,91e2d22682262c2e
X-Google-Attributes: gid111d45,public
From: Thomas Denn <denntm@earthlink.net>
Subject: Re: Buttons in JTable
Date: 2000/06/20
Message-ID: <39502C7D.492E46DA@earthlink.net>
X-Deja-AN: 637052033
Content-Transfer-Encoding: 7bit
References: <3949e5cb@dnews> <MPG.13b4ca55ff6c6cb39899d5@forums.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Trace: 20 Jun 2000 19:35:08 -0800, 38.30.235.148
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing