Thread Subject: Changing cell color in uitable

Subject: Changing cell color in uitable

From: YP

Date: 19 Jun, 2007 08:22:30

Message: 1 of 8

Hello!
Is it possible to change background color of the particular cell in
uitable? If so how? Specifically I want to color the cell using user
provided RGB values.
I am using MATLAB 7.0.4.365 (R14) Service Pack 2 and Java 1.5.0 with
Sun Microsystems Inc. Java HotSpot(TM) Client VM
(mixed mode)

I no very little Java and swing programming. I saw other posts
related to coloring columns but then coloring cell was not very
obvious.

with regards,
YP
---

Subject: Changing cell color in uitable

From: Yair Altman

Date: 19 Jun, 2007 08:58:18

Message: 2 of 8

YP wrote:
>
> Hello!
> Is it possible to change background color of the particular cell in
> uitable? If so how? Specifically I want to color the cell using
> user provided RGB values.
> I am using MATLAB 7.0.4.365 (R14) Service Pack 2 and Java 1.5.0
> with Sun Microsystems Inc. Java HotSpot(TM) Client VM
> (mixed mode)
>
> I no very little Java and swing programming. I saw other posts
> related to coloring columns but then coloring cell was not very
> obvious.
>
> with regards,
> YP
  

Unfortunately, if you want to color specific cells based on content
or some other logic, you need to define a user-class in Java. It's
not difficult, but you need to know Java for this.

Yair Altman

Subject: Changing cell color in uitable

From: YP

Date: 20 Jun, 2007 03:20:58

Message: 3 of 8

Hello!
Is it possible to provide me with a code snippet?
with regards,
YP
----

 Yair Altman wrote:
> Unfortunately, if you want to color specific cells based on content
> or some other logic, you need to define a user-class in Java. It's
> not difficult, but you need to know Java for this.
>
> Yair Altman

Subject: Changing cell color in uitable

From: Yair Altman

Date: 20 Jun, 2007 05:02:53

Message: 4 of 8

YP wrote:
>
> Hello!
> Is it possible to provide me with a code snippet?
> with regards,
> YP
> ----
>
> Yair Altman wrote:
>> Unfortunately, if you want to color specific cells based on
> content or some other logic, you need to define a user-class in
> Java. It's not difficult, but you need to know Java for this.
>>
>> Yair Altman
  

You asked for it...

ColoredFieldCellRenderer.java:
==============================

// ColoredFieldCellRenderer - Modified TableCellRenderer for
input-file fields drop-down cells

// Programmed by Yair M. Altman: altmany(at)gmail.com
// $Revision: 1.6 $ $Date: 2007/05/07 07:26:40 $

import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;

public class ColoredFieldCellRenderer extends
DefaultTableCellRenderer implements TableCellRenderer
{
private Color _bgcolor = getBackground();
private int _eventTypeLookupColumn = -1;
private boolean _debug = false;
private boolean _disabled = false;
private Color _disabledColor = new Color(0.925F, 0.914F, 0.847F);
// gray
private Hashtable _cellBgColorHashtable = new Hashtable();
private Hashtable _cellTooltipHashtable = new Hashtable();

public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int column)
{
JComponent cell = (JComponent)
super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
if (_debug) System.out.println(row + "," + column + " => value:
" + value);

// Field cells may not be empty - indicate with the chosen bgcolor
boolean emptyCell = false;
String valueStr = "" + value;
if ((value == null) || (valueStr.trim().length() == 0))
{
emptyCell = true;
cell.setBackground(_bgcolor);
} else {
//valueStr = (String) value;
cell.setBackground(Color.white);
}

// If this field is irrelevant to the eventType, disable it and
indicate with a gray bgcolor
if (_eventTypeLookupColumn >= 0)
{
String eventType = (String)
table.getValueAt(row,_eventTypeLookupColumn);
if (_debug) System.out.println(row + "," + column + " =>
eventType: " + eventType);
if ((eventType != null) && (eventType.equals("Target")) &&
((column == 6) || (column == 7))) // "Data Field/Value" columns
{
cell.disable();
cell.setBackground(_disabledColor);
//table.setValueAt("N/A",row,6);
if ((valueStr == null) || (!valueStr.equals("N/A")))
{
//setText("N/A");
table.setValueAt("N/A",row,column);
}
} else {
cell.enable();
}
}
if (_disabled)
{
cell.disable();
cell.setBackground(_bgcolor);
}

// If this cell should have a specific color, then use it
Vector rowColVector = getRowColVector(row, column);
Color cellBgColor = (Color)
_cellBgColorHashtable.get(rowColVector);
if (cellBgColor != null)
cell.setBackground(cellBgColor);

// If this cell is selected, then highlight with a light-blue color
if (isSelected) // && !(cell.getBackground().equals(Color.white)))
{
//cell.setBackground(cell.getBackground().darker());
float[] rgb = cell.getBackground().getRGBComponents(null);
rgb[0] *= .8;
rgb[1] *= .8; // darken the R&G components only, to highlight the
blue component
cell.setBackground(new Color(rgb[0],rgb[1],rgb[2]));
cell.setForeground(Color.black);
}

// If this cell should have a specific tooltip, then use it
String cellTooltip = (String)
_cellTooltipHashtable.get(rowColVector);
if ((cellTooltip == null) || (cellTooltip.length() == 0))
{
// No specific tooltip set, so use the cell's string value as the
tooltip
if (value == null)
cell.setToolTipText(null);
else if (valueStr.length() > 200)
{
// Split long tooltip text into several smaller lines
String tipText = "<html>";
int MAX_CHARS_PER_LINE = 150;
int strLen = valueStr.length();
for (int lineIdx=0; lineIdx <= strLen/MAX_CHARS_PER_LINE;
lineIdx++)
tipText =
tipText.concat(valueStr.substring(lineIdx*MAX_CHARS_PER_LINE,Math.min(
(lineIdx+1)*MAX_CHARS_PER_LINE,strLen))).concat("<br>");
cell.setToolTipText(tipText);
}
else
cell.setToolTipText(valueStr);
}
else
{
cell.setToolTipText(cellTooltip);
}

return cell;
}

public ColoredFieldCellRenderer()
{
this(new Color(0.925F, 0.914F, 0.847F)); // gray
}

public ColoredFieldCellRenderer(Color bgcolor)
{
super();
_bgcolor = bgcolor;
//setOpaque(false);
setBackground(_bgcolor);
}

public ColoredFieldCellRenderer(float[] rgb)
{
super();
_bgcolor = new Color(rgb[0], rgb[1], rgb[2]);
setBackground(_bgcolor);
}

public ColoredFieldCellRenderer(float r, float g, float b)
{
super();
_bgcolor = new Color(r,g,b);
setBackground(_bgcolor);
}

public Color getBgColor()
{
return _bgcolor;
}

public void setBgColor(Color color)
{
_bgcolor = color;
setBackground(_bgcolor);
}

public void setBgColor(float[] rgb)
{
_bgcolor = new Color(rgb[0], rgb[1], rgb[2]);
setBackground(_bgcolor);
}

public void setBgColor(float r, float g, float b)
{
_bgcolor = new Color(r,g,b);
setBackground(_bgcolor);
}

public void resetBgColors()
{
        _cellBgColorHashtable.clear();
}

public void resetTooltips()
{
        _cellTooltipHashtable.clear();
}

public void setCellBgColor(int row, int column, Color color)
{
Vector rowColVector = getRowColVector(row, column);
if (color == null)
color = Color.white; // Hashtables cannot
accept nulls...
_cellBgColorHashtable.put(rowColVector, color);
}

public void setCellTooltip(int row, int column, String text)
{
Vector rowColVector = getRowColVector(row, column);
//System.out.println(row + "," + column + " => value: " + text);
if (text == null)
text = ""; // Hashtables cannot
accept nulls...
_cellTooltipHashtable.put(rowColVector, text);
}

public Color getCellBgColor(int row, int column)
{
Vector rowColVector = getRowColVector(row, column);
return (Color) _cellBgColorHashtable.get(rowColVector);
}

public String getCellTooltip(int row, int column)
{
Vector rowColVector = getRowColVector(row, column);
return (String) _cellTooltipHashtable.get(rowColVector);
}

private Vector getRowColVector(int row, int column)
{
Vector rowColVector = new Vector();
rowColVector.addElement(new Integer(row));
rowColVector.addElement(new Integer(column));
return rowColVector;
}

public void setDebug(boolean flag)
{
_debug = flag;
}

public void setDisabled(boolean flag)
{
_disabled = flag;
}

public void setEventTypeLookupColumn(int column)
{
_eventTypeLookupColumn = column;
}
}

Sample usage in Matlab:
=======================
      warningBgColor = java.awt.Color(1,.4,.4); % light-red
      c = ColoredFieldCellRenderer(warningBgColor);
      table.getColumnModel.getColumn(1).setCellRenderer(c);
      c.setCellBgColor(row,column,warningBgColor);

Yair Altman

Subject: Changing cell color in uitable

From: YP

Date: 20 Jun, 2007 11:14:07

Message: 5 of 8

Hello Yair!
Thank you for the code.
YP
-
 Yair Altman wrote:

> You asked for it...
>
> ColoredFieldCellRenderer.java:
> ==============================
>
> // ColoredFieldCellRenderer - Modified TableCellRenderer for
> input-file fields drop-down cells
>
> // Programmed by Yair M. Altman: altmany(at)gmail.com
> // $Revision: 1.6 $ $Date: 2007/05/07 07:26:40 $
>
> import java.awt.*;
> import java.util.*;
> import javax.swing.*;
> import javax.swing.table.*;
>
> public class ColoredFieldCellRenderer extends
> DefaultTableCellRenderer implements TableCellRenderer
> {
> private Color _bgcolor = getBackground();
> private int _eventTypeLookupColumn = -1;
> private boolean _debug = false;
> private boolean _disabled = false;
> private Color _disabledColor = new Color(0.925F, 0.914F, 0.847F);
> // gray
> private Hashtable _cellBgColorHashtable = new Hashtable();
> private Hashtable _cellTooltipHashtable = new Hashtable();
>
> public Component getTableCellRendererComponent(JTable table,
> Object
> value, boolean isSelected, boolean hasFocus, int row, int column)
> {
> JComponent cell = (JComponent)
> super.getTableCellRendererComponent(table, value, isSelected,
> hasFocus, row, column);
> if (_debug) System.out.println(row + "," + column + " =>
> value:
> " + value);
>
> // Field cells may not be empty - indicate with the chosen
> bgcolor
> boolean emptyCell = false;
> String valueStr = "" + value;
> if ((value == null) || (valueStr.trim().length() == 0))
> {
> emptyCell = true;
> cell.setBackground(_bgcolor);
> } else {
> //valueStr = (String) value;
> cell.setBackground(Color.white);
> }
>
> // If this field is irrelevant to the eventType, disable it and
> indicate with a gray bgcolor
> if (_eventTypeLookupColumn >= 0)
> {
> String eventType = (String)
> table.getValueAt(row,_eventTypeLookupColumn);
> if (_debug) System.out.println(row + "," + column + " =>
> eventType: " + eventType);
> if ((eventType != null) && (eventType.equals("Target")) &&
> ((column == 6) || (column == 7))) // "Data Field/Value" columns
> {
> cell.disable();
> cell.setBackground(_disabledColor);
> //table.setValueAt("N/A",row,6);
> if ((valueStr == null) || (!valueStr.equals("N/A")))
> {
> //setText("N/A");
> table.setValueAt("N/A",row,column);
> }
> } else {
> cell.enable();
> }
> }
> if (_disabled)
> {
> cell.disable();
> cell.setBackground(_bgcolor);
> }
>
> // If this cell should have a specific color, then use it
> Vector rowColVector = getRowColVector(row, column);
> Color cellBgColor = (Color)
> _cellBgColorHashtable.get(rowColVector);
> if (cellBgColor != null)
> cell.setBackground(cellBgColor);
>
> // If this cell is selected, then highlight with a light-blue
> color
> if (isSelected) // &&
> !(cell.getBackground().equals(Color.white)))
> {
> //cell.setBackground(cell.getBackground().darker());
> float[] rgb = cell.getBackground().getRGBComponents(null);
> rgb[0] *= .8;
> rgb[1] *= .8; // darken the R&G components only, to highlight
> the
> blue component
> cell.setBackground(new Color(rgb[0],rgb[1],rgb[2]));
> cell.setForeground(Color.black);
> }
>
> // If this cell should have a specific tooltip, then use it
> String cellTooltip = (String)
> _cellTooltipHashtable.get(rowColVector);
> if ((cellTooltip == null) || (cellTooltip.length() == 0))
> {
> // No specific tooltip set, so use the cell's string value as
> the
> tooltip
> if (value == null)
> cell.setToolTipText(null);
> else if (valueStr.length() > 200)
> {
> // Split long tooltip text into several smaller lines
> String tipText = "<html>";
> int MAX_CHARS_PER_LINE = 150;
> int strLen = valueStr.length();
> for (int lineIdx=0; lineIdx <= strLen/MAX_CHARS_PER_LINE;
> lineIdx++)
> tipText =
>
tipText.concat(valueStr.substring(lineIdx*MAX_CHARS_PER_LINE,Math.mi
> n(
> (lineIdx+1)*MAX_CHARS_PER_LINE,strLen))).concat("<br>");
> cell.setToolTipText(tipText);
> }
> else
> cell.setToolTipText(valueStr);
> }
> else
> {
> cell.setToolTipText(cellTooltip);
> }
>
> return cell;
> }
>
> public ColoredFieldCellRenderer()
> {
> this(new Color(0.925F, 0.914F, 0.847F)); // gray
> }
>
> public ColoredFieldCellRenderer(Color bgcolor)
> {
> super();
> _bgcolor = bgcolor;
> //setOpaque(false);
> setBackground(_bgcolor);
> }
>
> public ColoredFieldCellRenderer(float[] rgb)
> {
> super();
> _bgcolor = new Color(rgb[0], rgb[1], rgb[2]);
> setBackground(_bgcolor);
> }
>
> public ColoredFieldCellRenderer(float r, float g, float b)
> {
> super();
> _bgcolor = new Color(r,g,b);
> setBackground(_bgcolor);
> }
>
> public Color getBgColor()
> {
> return _bgcolor;
> }
>
> public void setBgColor(Color color)
> {
> _bgcolor = color;
> setBackground(_bgcolor);
> }
>
> public void setBgColor(float[] rgb)
> {
> _bgcolor = new Color(rgb[0], rgb[1], rgb[2]);
> setBackground(_bgcolor);
> }
>
> public void setBgColor(float r, float g, float b)
> {
> _bgcolor = new Color(r,g,b);
> setBackground(_bgcolor);
> }
>
> public void resetBgColors()
> {
> _cellBgColorHashtable.clear();
> }
>
> public void resetTooltips()
> {
> _cellTooltipHashtable.clear();
> }
>
> public void setCellBgColor(int row, int column, Color color)
> {
> Vector rowColVector = getRowColVector(row, column);
> if (color == null)
> color = Color.white; // Hashtables
> cannot
> accept nulls...
> _cellBgColorHashtable.put(rowColVector, color);
> }
>
> public void setCellTooltip(int row, int column, String text)
> {
> Vector rowColVector = getRowColVector(row, column);
> //System.out.println(row + "," + column + " => value: " +
> text);
> if (text == null)
> text = ""; // Hashtables cannot
> accept nulls...
> _cellTooltipHashtable.put(rowColVector, text);
> }
>
> public Color getCellBgColor(int row, int column)
> {
> Vector rowColVector = getRowColVector(row, column);
> return (Color) _cellBgColorHashtable.get(rowColVector);
> }
>
> public String getCellTooltip(int row, int column)
> {
> Vector rowColVector = getRowColVector(row, column);
> return (String) _cellTooltipHashtable.get(rowColVector);
> }
>
> private Vector getRowColVector(int row, int column)
> {
> Vector rowColVector = new Vector();
> rowColVector.addElement(new Integer(row));
> rowColVector.addElement(new Integer(column));
> return rowColVector;
> }
>
> public void setDebug(boolean flag)
> {
> _debug = flag;
> }
>
> public void setDisabled(boolean flag)
> {
> _disabled = flag;
> }
>
> public void setEventTypeLookupColumn(int column)
> {
> _eventTypeLookupColumn = column;
> }
> }
>
> Sample usage in Matlab:
> =======================
> warningBgColor = java.awt.Color(1,.4,.4); % light-red
> c = ColoredFieldCellRenderer(warningBgColor);
> table.getColumnModel.getColumn(1).setCellRenderer(c);
> c.setCellBgColor(row,column,warningBgColor);
>
> Yair Altman

Subject: Changing cell color in uitable

From: Kunjesh shah

Date: 24 Jun, 2009 13:52:01

Message: 6 of 8

Hi,
Can anyone help me? code which is provided below is not working for me . it is saying error when i call java class in to my matlab '*.m' file. it does not recognizes ' table.getColumnModel.getColumn(1).setCellRenderer(c);' . I dont know java much, and i m also beginner with matlab guide. i want to color my each cell based on some logic.
so if anyone can help me with this, will be very much appreciated.

Thanks
YP <yogeshparte@HOTMAIL.COM> wrote in message <ef5b1e4.3@webcrossing.raydaftYaTP>...
> Hello Yair!
> Thank you for the code.
> YP
> -
> Yair Altman wrote:
>
> > You asked for it...
> >
> > ColoredFieldCellRenderer.java:
> > ==============================
> >
> > // ColoredFieldCellRenderer - Modified TableCellRenderer for
> > input-file fields drop-down cells
> >
> > // Programmed by Yair M. Altman: altmany(at)gmail.com
> > // $Revision: 1.6 $ $Date: 2007/05/07 07:26:40 $
> >
> > import java.awt.*;
> > import java.util.*;
> > import javax.swing.*;
> > import javax.swing.table.*;
> >
> > public class ColoredFieldCellRenderer extends
> > DefaultTableCellRenderer implements TableCellRenderer
> > {
> > private Color _bgcolor = getBackground();
> > private int _eventTypeLookupColumn = -1;
> > private boolean _debug = false;
> > private boolean _disabled = false;
> > private Color _disabledColor = new Color(0.925F, 0.914F, 0.847F);
> > // gray
> > private Hashtable _cellBgColorHashtable = new Hashtable();
> > private Hashtable _cellTooltipHashtable = new Hashtable();
> >
> > public Component getTableCellRendererComponent(JTable table,
> > Object
> > value, boolean isSelected, boolean hasFocus, int row, int column)
> > {
> > JComponent cell = (JComponent)
> > super.getTableCellRendererComponent(table, value, isSelected,
> > hasFocus, row, column);
> > if (_debug) System.out.println(row + "," + column + " =>
> > value:
> > " + value);
> >
> > // Field cells may not be empty - indicate with the chosen
> > bgcolor
> > boolean emptyCell = false;
> > String valueStr = "" + value;
> > if ((value == null) || (valueStr.trim().length() == 0))
> > {
> > emptyCell = true;
> > cell.setBackground(_bgcolor);
> > } else {
> > //valueStr = (String) value;
> > cell.setBackground(Color.white);
> > }
> >
> > // If this field is irrelevant to the eventType, disable it and
> > indicate with a gray bgcolor
> > if (_eventTypeLookupColumn >= 0)
> > {
> > String eventType = (String)
> > table.getValueAt(row,_eventTypeLookupColumn);
> > if (_debug) System.out.println(row + "," + column + " =>
> > eventType: " + eventType);
> > if ((eventType != null) && (eventType.equals("Target")) &&
> > ((column == 6) || (column == 7))) // "Data Field/Value" columns
> > {
> > cell.disable();
> > cell.setBackground(_disabledColor);
> > //table.setValueAt("N/A",row,6);
> > if ((valueStr == null) || (!valueStr.equals("N/A")))
> > {
> > //setText("N/A");
> > table.setValueAt("N/A",row,column);
> > }
> > } else {
> > cell.enable();
> > }
> > }
> > if (_disabled)
> > {
> > cell.disable();
> > cell.setBackground(_bgcolor);
> > }
> >
> > // If this cell should have a specific color, then use it
> > Vector rowColVector = getRowColVector(row, column);
> > Color cellBgColor = (Color)
> > _cellBgColorHashtable.get(rowColVector);
> > if (cellBgColor != null)
> > cell.setBackground(cellBgColor);
> >
> > // If this cell is selected, then highlight with a light-blue
> > color
> > if (isSelected) // &&
> > !(cell.getBackground().equals(Color.white)))
> > {
> > //cell.setBackground(cell.getBackground().darker());
> > float[] rgb = cell.getBackground().getRGBComponents(null);
> > rgb[0] *= .8;
> > rgb[1] *= .8; // darken the R&G components only, to highlight
> > the
> > blue component
> > cell.setBackground(new Color(rgb[0],rgb[1],rgb[2]));
> > cell.setForeground(Color.black);
> > }
> >
> > // If this cell should have a specific tooltip, then use it
> > String cellTooltip = (String)
> > _cellTooltipHashtable.get(rowColVector);
> > if ((cellTooltip == null) || (cellTooltip.length() == 0))
> > {
> > // No specific tooltip set, so use the cell's string value as
> > the
> > tooltip
> > if (value == null)
> > cell.setToolTipText(null);
> > else if (valueStr.length() > 200)
> > {
> > // Split long tooltip text into several smaller lines
> > String tipText = "<html>";
> > int MAX_CHARS_PER_LINE = 150;
> > int strLen = valueStr.length();
> > for (int lineIdx=0; lineIdx <= strLen/MAX_CHARS_PER_LINE;
> > lineIdx++)
> > tipText =
> >
> tipText.concat(valueStr.substring(lineIdx*MAX_CHARS_PER_LINE,Math.mi
> > n(
> > (lineIdx+1)*MAX_CHARS_PER_LINE,strLen))).concat("<br>");
> > cell.setToolTipText(tipText);
> > }
> > else
> > cell.setToolTipText(valueStr);
> > }
> > else
> > {
> > cell.setToolTipText(cellTooltip);
> > }
> >
> > return cell;
> > }
> >
> > public ColoredFieldCellRenderer()
> > {
> > this(new Color(0.925F, 0.914F, 0.847F)); // gray
> > }
> >
> > public ColoredFieldCellRenderer(Color bgcolor)
> > {
> > super();
> > _bgcolor = bgcolor;
> > //setOpaque(false);
> > setBackground(_bgcolor);
> > }
> >
> > public ColoredFieldCellRenderer(float[] rgb)
> > {
> > super();
> > _bgcolor = new Color(rgb[0], rgb[1], rgb[2]);
> > setBackground(_bgcolor);
> > }
> >
> > public ColoredFieldCellRenderer(float r, float g, float b)
> > {
> > super();
> > _bgcolor = new Color(r,g,b);
> > setBackground(_bgcolor);
> > }
> >
> > public Color getBgColor()
> > {
> > return _bgcolor;
> > }
> >
> > public void setBgColor(Color color)
> > {
> > _bgcolor = color;
> > setBackground(_bgcolor);
> > }
> >
> > public void setBgColor(float[] rgb)
> > {
> > _bgcolor = new Color(rgb[0], rgb[1], rgb[2]);
> > setBackground(_bgcolor);
> > }
> >
> > public void setBgColor(float r, float g, float b)
> > {
> > _bgcolor = new Color(r,g,b);
> > setBackground(_bgcolor);
> > }
> >
> > public void resetBgColors()
> > {
> > _cellBgColorHashtable.clear();
> > }
> >
> > public void resetTooltips()
> > {
> > _cellTooltipHashtable.clear();
> > }
> >
> > public void setCellBgColor(int row, int column, Color color)
> > {
> > Vector rowColVector = getRowColVector(row, column);
> > if (color == null)
> > color = Color.white; // Hashtables
> > cannot
> > accept nulls...
> > _cellBgColorHashtable.put(rowColVector, color);
> > }
> >
> > public void setCellTooltip(int row, int column, String text)
> > {
> > Vector rowColVector = getRowColVector(row, column);
> > //System.out.println(row + "," + column + " => value: " +
> > text);
> > if (text == null)
> > text = ""; // Hashtables cannot
> > accept nulls...
> > _cellTooltipHashtable.put(rowColVector, text);
> > }
> >
> > public Color getCellBgColor(int row, int column)
> > {
> > Vector rowColVector = getRowColVector(row, column);
> > return (Color) _cellBgColorHashtable.get(rowColVector);
> > }
> >
> > public String getCellTooltip(int row, int column)
> > {
> > Vector rowColVector = getRowColVector(row, column);
> > return (String) _cellTooltipHashtable.get(rowColVector);
> > }
> >
> > private Vector getRowColVector(int row, int column)
> > {
> > Vector rowColVector = new Vector();
> > rowColVector.addElement(new Integer(row));
> > rowColVector.addElement(new Integer(column));
> > return rowColVector;
> > }
> >
> > public void setDebug(boolean flag)
> > {
> > _debug = flag;
> > }
> >
> > public void setDisabled(boolean flag)
> > {
> > _disabled = flag;
> > }
> >
> > public void setEventTypeLookupColumn(int column)
> > {
> > _eventTypeLookupColumn = column;
> > }
> > }
> >
> > Sample usage in Matlab:
> > =======================
> > warningBgColor = java.awt.Color(1,.4,.4); % light-red
> > c = ColoredFieldCellRenderer(warningBgColor);
> > table.getColumnModel.getColumn(1).setCellRenderer(c);
> > c.setCellBgColor(row,column,warningBgColor);
> >
> > Yair Altman

Subject: Changing cell color in uitable

From: Camron Call

Date: 11 Jul, 2009 20:52:03

Message: 7 of 8

table.getColumnModel.getColumn(1).setCellRenderer(c);

I am having the same problem as Kunjesh. I have compiled the .java code to a .class and placed it in the path. But since the variable 'table' is not in the matlab workspace so it won't work like this. There has to be a way to set the renderer 'c' as the renderer of the specific uitable (for example) uitable1 in the Guide GUI.
If someone knows how this can be fixed, more than one of us will be really happy.
Please?

Camron

Subject: Changing cell color in uitable

From: Camron Call

Date: 27 Aug, 2009 05:26:00

Message: 8 of 8

Just in case anyone is interested...

My GUI table is only used to display information and is not editable so this was a great solution for me.

Clement Val sent me this:

Simply, the uitable supports HTML, so you just have to put something like '<html><span style="background-color: #AABBCC;">your content here</span></html>' in the data field, and the background color is changed. However, if the field needs to be editable, this won't work : as soon as he clicks it, the user displays and edits everything, including the html code.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
html Camron Call 27 Aug, 2009 01:29:06
uitable Yogesh 11 Feb, 2008 16:46:58
cell color Yogesh 11 Feb, 2008 16:46:58
uitable Yogesh 11 Feb, 2008 16:46:35
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com