Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:38:24+00:00 2026-06-15T05:38:24+00:00

Often when using JTable or JTree , user define its own cell renderer. It

  • 0

Often when using JTable or JTree, user define its own cell renderer.

It is very common to inherit user’s component from DefaultTableCellRenderer, and implements the renderer method getTableCellRendererComponent. It turns out that DefaultTableCellRenderer in fact inherits from JLabel, thus returns itself (this) when called to super (at the render method) and thus user’s renderer can similarly returns itself (this) as well.

And it all works well.

My question is how can it be?

Each time this method is called by the table, it is given different parameters, and the output label is changed as function of these parameters. If it is indeed the same instance of the label – shouldn’t it be changed according to the last call to this method?
Wouldn’t it mean that all of the table’s cells are infect composed of the same label instance, which holds the same value (value of last call to the renderer method)?

I have searched the web, and dig within Swing’s code, and could not find any act of clone or copy constructor that actually duplicates the output label.
I could not find any evidence that (perhaps) swing uses reflection in order to re-instantiate the renderer each time from scratch.

I have read the Swing’s tutorial on JTables, and there I could find the next lines:

You might expect each cell in a table to be a component. However, for performance reasons, Swing tables are implemented differently.
Instead, a single cell renderer is generally used to draw all of the cells that contain the same type of data. You can think of the renderer as a configurable ink stamp that the table uses to stamp appropriately formatted data onto each cell. When the user starts to edit a cell’s data, a cell editor takes over the cell, controlling the cell’s editing behavior.

They give a hint, that indeed what I am saying is correct, but do not explain how its actually being accomplished.

I can’t get it. Can any of you?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:38:25+00:00Added an answer on June 15, 2026 at 5:38 am

    It’s an implementation of the flyweight pattern.

    When the JTable repaints itself, it starts a loop and iterates over every cell that must be painted.

    For each cell, it invokes the renderer with the arguments corresponding to the cell. The renderer returns a component. This component is painted in the rectangle corresponding to the current table cell.

    Then the renderer is called for the next cell, and the returned component (which has a different text and color, for example), is painted in the rectangle corresponding to the cell, etc.

    Imagine that each time the renderer is called, a screenshot of the returned component is taken and pasted into the table cell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application often fetch data from a webpage using WebRequest, but it isn't possible
I'm often using do - while(0) constructs in my #define s, for the reasons
Since I've discovered this snippet, I'm very often using it for iterating over arrays
I have JQuery Twitter api plugin I have been using often from site to
I often (using the mouse) switch between 1 of 3 favorite folders under my
While doing some refactoring I've found that I'm quite often using a pair or
I often get to the question when using a service, should I find a
I'm using SVN (TortoiseSVN) and often came into the following situation: I wanted to
I often end up writing a bit of code twice when using a loops.
I often hear things like Can we load our employee info using LDAP? Yet,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.