• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help needed from Julie Stella

 
wip siva
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you don't want any of the rest of us to answer this question???
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're talking about changing the color of a row in a JTable, I've done it.
 
wip siva
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Julie Stella
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!