hi buddy i saw ur reply.thanx a lot.still i am waiting for ur reply. plz give me the sample. to change the color of one particular row. my id is 123knock@usa.net
hi friends thanx a lot for ur interest. atlast i have achieved it. don't mistake me.julie has some sample code. that's why i asked. anyway thanx keep in touch bye
Here's the code...hope I am getting back to you in time. This code has a bunch of other stuff in it...I'll trust that you are able to filter it out. What you need to do is to override getTableCellRendererComponent() then get the renderer and set the background/forground. In my code, we were checking all sorts of conditions before setting the color of the row so ignore all that. Just get the renderer and setBackground/Foreground. Hope this helps! Stella package securecomputing.troller.gui; import javax.swing.*; import javax.swing.table.*; import java.awt.*; import securecomputing.troller.gui.shared.SBResources; public class PolicyTableCellRenderer extends DefaultTableCellRenderer implements IPolicyConstants { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component renderer = null; if (!((RuleTable)table).isActionApplicable(row, column)) { try { String newValue = (String)value + " " + SBResources.getString( SBResources.fields, "notApplicable.abbreviation"); value = newValue; } catch (ClassCastException e) {} } if (table == null) { return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } if (value instanceof Boolean){ TableCellEditor editor = table.getDefaultEditor(value.getClass()); renderer = editor.getTableCellEditorComponent(table, value, isSelected, row, column); } else { renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } ((JLabel)renderer).setOpaque(true); if (isSelected) { // All selected rules are rendered in the same color. renderer.setBackground(SELECTED_RULE_BACKGROUND_COLOR); renderer.setForeground(Color.white); } else if (table.getModel() instanceof PolicyTableModel && ((PolicyTableModel)table.getModel()).isRuleSet(row)) { // An unselected rule set or its subrule. renderer.setBackground(RULE_SET_BACKGROUND_COLOR); renderer.setForeground(Color.white); } else if(((RuleSetTableModel)table.getModel()).isRowEnabled(row)) { // An unselected, enabled regular rule renderer.setBackground(Color.white); renderer.setForeground(Color.black); } else { // An unselected, disabled regular rule renderer.setBackground(DISABLED_RULE_BACKGROUND_COLOR); renderer.setForeground(Color.black); } return renderer; } }
Post by:autobot
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, that will fit in a stocking