Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get the actual component rendered in the JTable Cell ?

1,863 views
Skip to first unread message

Sekhri Lotfi

unread,
Jul 29, 2009, 12:23:01 PM7/29/09
to
Hello,

I have a custom cell render for a JTable.
I create for each cell a JPanel that contains a JLabel and a JButton.

Question is, How can I get the actual rendered component object (the
JPanel) of a cell for a given row and column index.

Thanks for help.


John B. Matthews

unread,
Jul 29, 2009, 2:09:37 PM7/29/09
to
In article
<53bcb610-84e7-4786...@18g2000yqa.googlegroups.com>,
Sekhri Lotfi <sekhri...@gmail.com> wrote:

I'm not sure what you're asking. I take it your renderer extends JPanel
and implements TableCellRenderer. Perhaps you can show an example that
illustrates what your trying to do.

The JTable method getCellRenderer(row, col) will return the default
renderer based on the type specified by your table's data model, using
getColumnClass(). After you set your custom renderer, getCellRenderer
will return a reference to your custom renderer.

There's more detail here:

<http://java.sun.com/docs/books/tutorial/uiswing/components/table.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Fred

unread,
Jul 29, 2009, 2:27:01 PM7/29/09
to


JPanel p = (JPanel)table.dataModel().getValueAt(row, column);

--
Fred K

Daniel Pitts

unread,
Jul 30, 2009, 10:35:53 AM7/30/09
to
That assumes that you are putting the actual JPanel objects into the
cell, which doesn't often make sense.

The correct answer is that the Component used to render a cell is often
only transient. Even if your getCellRendererComponent method returns a
new instance every time, it is thrown away after it is used to render.

If it returns the *same* instance every time (as is a common idiom),
then it is re-used, but not held on to.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Roedy Green

unread,
Jul 31, 2009, 8:16:07 AM7/31/09
to
On Wed, 29 Jul 2009 09:23:01 -0700 (PDT), Sekhri Lotfi
<sekhri...@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>
>Question is, How can I get the actual rendered component object (the
>JPanel) of a cell for a given row and column index.

It does not exist. The same component is recycled to render each
cell.
--
Roedy Green Canadian Mind Products
http://mindprod.com

The USA and Iraq are as mismatched combatants as Mike Tyson and a bag lady. Americans make themselves look ridiculous when they justify invading and occupying Iraq in self defence.

0 new messages