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 9068171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:07:40+00:00 2026-06-16T17:07:40+00:00

I am putting some icons in my jtable’s cell but problem is it is

  • 0

I am putting some icons in my jtable’s cell but problem is it is changing it’s background color to table’s background color….i want it to change it to row’s background color…and also when it is selected it does’t show the selection…Here is my code how i am setting icons….

 Users user;
 ConsoleUsersListTbl.getColumnModel().getColumn(1).setCellRenderer(new ImageRender());


    DefaultTableModel userTableModel = (DefaultTableModel) ConsoleUsersListTbl.getModel();

    for (int i = 0; i < userList.size()-1; i++) {

        user = userList.get(i);
        javax.swing.ImageIcon image_icon = new javax.swing.ImageIcon(user.getUser_image());
        if (image_icon.getIconWidth() > 32 || image_icon.getIconWidth() > 32) {
            InputStream in = new ByteArrayInputStream(user.getUser_image());
            BufferedImage buff_image;
            try {
                buff_image = ImageIO.read(in);
                int type = buff_image.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : buff_image.getType();
                BufferedImage resizedImage = resizeImage(buff_image, type);

                image_icon.setImage(resizedImage);
                userTableModel.setValueAt(image_icon, i, 1);

            } catch (IOException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            userTableModel.setValueAt(image_icon, i, 1);
        }

and here is the out put……
enter image description here

Edit1
here is my Image Render class ;and making setOpaque true makes my icons white..

public class ImageRender extends  DefaultTableCellRenderer {
JLabel lable = new JLabel();
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    lable.setIcon((ImageIcon)value);
    lable.setOpaque(true);
    return lable;
}
}
  • 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-16T17:07:41+00:00Added an answer on June 16, 2026 at 5:07 pm

    I think you need to implement the custom cell renderer as discussed here and also described here. The renderer has access to information if the current cell is focused or selected, so you can adjust background, foreground or even content any way you want. Mind that components may be opaque (have they own background) or not (the parent background or other content is visible through it). This is controlled through setOpaque(boolean).

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

Sidebar

Related Questions

I've used some jQuery UI sortable plugins but I always found the same problem,
Guys.. I want my html div not to resize after putting some text.. as
I'm putting some page content (which has been run through Tidy, but doesn't need
I am putting some heavy though into re-writing the data access layer in my
I was just putting some thought into different languages (as I'm reviewing for final
I try to optimize my pages by putting some async attributes on my scripts.
I need some help putting together this query in Django. I've simplified the example
Just putting part of some code here where I am writing two values to
Update Putting this at the top because it is crazy :) So some users
I'm trying to simplify some code by putting the ViewModel models into the code

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.