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

  • Home
  • SEARCH
  • 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 8523901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:32:29+00:00 2026-06-11T07:32:29+00:00

I have a JTable with 3 columns in it. 1. Icon, 2. Name of

  • 0

I have a JTable with 3 columns in it. 1. Icon, 2. Name of file or folder, 3. File type or “Folder”. I draw the Icon using a JLabel (I set background + png image) within the getTableCellRendererComponent method. Initially I draw an alternating background of the JLable either “white” or “grey” since those are the colors that the JTable Swing component alternates to draw the table. Now, when I select a row, the Icon (the first column) background does not get redrawn to “dark blue” same as the rest of the row. Illustrative Screenshot

Here are my questions:

General
1) How can also highlight the Icon cell when highlighting a row (pointers will suffice, no code expected)?

Specific

1.1) Do I have to use JLabel? Why can’t I just e.g. .SetValueAt("image.png",0,0)

1.2) I tried the getColumnClass(...) but that seems to redraw ALL cells in a given column. Is that expected?

Thanks.

  • 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-11T07:32:30+00:00Added an answer on June 11, 2026 at 7:32 am

    1.) The javax.swing.table.TableCellRenderer gets an isSelected parameter when it is called. You can easily write your own TableCellRenderer by inheriting from JLabel (for example) and overridding getTableCellRendererComponent: Adjust the Object and return this. Having your own renderer also allows you to set a breakpoint and really understand what is happening.

    1.1 + 1.2.) Both setValueAt and getColumnClass are part if the model and will probably not solve your problem with the selected background.

    You do not have to use JLabel: If you look at the return type from getTableCellRendererComponent you notice it is Component (not even JComponent). I guess JLabel is just customary because it normally has all the features you want for the renderer and the DefaultTableCellRenderer also uses JLabel. For the most freedom I advise you to use JComponent and write your own paintComponent, but in this case you probably don’t have to do that.

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

Sidebar

Related Questions

I have a jTable with two columns.First column is set as Boolean(for checkbox) and
I have set up a JTable and have made it to contain 18 columns.
I have a JTable and to set a picture as background in JTable and
I have a JTable with 3 columns. I've set the TableCellRenderer for all the
I have a JTable with few columns that are painted as checkboxes. What I
I have a JTable with two columns and both are JComboBox, for this purpose
I have a JTable with 2 columns, this JTable has N row (where N
I have a JTable inside a JScrollPane. In one of the columns in the
In my JTable, I have two editable numeric columns. The editor for both columns
In my implementation of JTable . I have to keep some columns editable and

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.