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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:02:54+00:00 2026-06-13T11:02:54+00:00

I want the ability to highlight some rows of JTable , depending on the

  • 0

I want the ability to highlight some rows of JTable, depending on the values in the row itself. For example, if the existing qty < reorder level, that row should be highlighted in the JTable.

I know there is a table method tblItems.setSelectionBackground(Color.yellow); that works when the rows are selected, but is there a similar method that doesn’t rely on the rows being selected to have them show in a different color?

public class MyTableCellRenderer implements TableCellRenderer {  
    @Override  
    public Component getTableCellRendererComponent
(JTable table, Object value, 
boolean isSelected, boolean hasFocus, int row, int column) {

        Object ob=table.getValueAt(row, column);
        if(ob.toString().equals("yes")){
            //need to colour the entire row
        }
        return 
    }

}
  • 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-13T11:02:54+00:00Added an answer on June 13, 2026 at 11:02 am

    you could use my answer to change the color of the cell. the same technique could be used to apply it to each cell in the row.

    This is also example with prepareRenderer

    import javax.swing.*;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.TableCellRenderer;
    import java.awt.*;
    
    public class TableWithPrepareRendererExample extends JFrame {
      ColorName colors[] = { new ColorName("Red"), new ColorName("Green"), new ColorName("Blue"),
        new ColorName("Black"), new ColorName("White") };
    
      public TableWithPrepareRendererExample() {
        super("Table With prepareRenderer Example");
        setSize(500, 300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    
        JTable table = new JTable(new AbstractTableModel() {
          ColorName data[] = { colors[0], colors[1], colors[2], colors[3], colors[4], colors[0],
            colors[1], colors[2], colors[3], colors[4] };
    
    
          public int getColumnCount() {
            return 3;
          }
    
          public int getRowCount() {
            return 10;
          }
    
          public Object getValueAt(int r, int c) {
            switch (c) {
              case 0:
                return (r + 1) + ".";
              case 1:
                return "Some pithy quote #" + r;
              case 2:
                return data[r];
            }
            return "Bad Column";
          }
    
          public Class getColumnClass(int c) {
            if (c == 2)
              return ColorName.class;
            return String.class;
          }
    
          public boolean isCellEditable(int r, int c) {
            return c == 2;
          }
    
          public void setValueAt(Object value, int r, int c) {
            data[r] = (ColorName) value;
          }
    
        }) {
          public Component prepareRenderer(TableCellRenderer renderer,
                                           int rowIndex, int vColIndex) {
            Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
            Object value = getValueAt(rowIndex, vColIndex);
            if (value.toString().equals("Red"))
              c.setBackground(Color.RED);
            else {
              if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) {
                c.setBackground(Color.YELLOW);
              } else {
                // If not shaded, match the table's background
                c.setBackground(getBackground());
              }
            }
            return c;
          }
        };
    
        JComboBox combo = new JComboBox(colors);
        table.setDefaultEditor(ColorName.class, new DefaultCellEditor(combo));
        table.setRowHeight(20);
        getContentPane().add(new JScrollPane(table));
      }
    
      public static void main(String args[]) {
        TableWithPrepareRendererExample ex = new TableWithPrepareRendererExample();
        ex.setVisible(true);
      }
    
      public class ColorName {
        String cname;
    
        public ColorName(String name) {
          cname = name;
        }
    
        public String toString() {
          return cname;
        }
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want the ability to uninstall an application from within itself. Example: UIAlertView pops
I have a php table and i want the ability to delete rows of
I want to provide the ability to save some rendered data/charts (with the titles
I am using jqGrid to render some data. Now I want the ability to
I want to ability to select code from my program such as dreamweaver or
I'm building an NSPredicateEditor , and I want the ability to do advanced date
How do I adding new aloha-button in aloha-multisplit-expanded box. (I want the ability to
I'm using CKEditor in a CMS I've built. I want use the ability to
I want to give my users the ability to choose how their public page
I want to print something like this (a 7-day calendar) but with the ability

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.