Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
gui tables and colors

Subject: gui tables and colors

From: sujata

Date: 6 Jun, 2011 08:26:04

Message: 1 of 4

Hi

I have a matrix 5 by 4 with number in it some positive some negative.
I would like to display these in a data_table. I did so but now I want to display the numbers that are negative in red and the numbers that are positive in black (which is default).. I mean the number itself and not the background color should be in red.

If I have the matrix I just use matrix < 0 to get a logical matrix to detect the negative numbers but then I get stuck translating it into the colors of a datatable inthe GUI.

can anyone help mewith this.

Subject: gui tables and colors

From: ImageAnalyst

Date: 6 Jun, 2011 19:40:31

Message: 2 of 4

On Jun 6, 4:26 am, "sujata" <sujat...@gmail.com> wrote:
> Hi
>
> I have a matrix 5 by 4 with number in it some positive some negative.
> I would like to display these in a data_table. I did so but now I want to display the numbers that are negative in red and the numbers that are positive in black (which is default).. I mean the number itself and not the background color should be in red.
>
> If I have the matrix I just use matrix < 0 to get a logical matrix to detect the negative numbers but then I get stuck translating it into the colors of a datatable inthe GUI.
>
> can anyone help mewith this.

----------------------------------------------------------------------------
Sounds like a question for Yair:
http://undocumentedmatlab.com/

Subject: gui tables and colors

From: matt dash

Date: 6 Jun, 2011 22:09:04

Message: 3 of 4

"sujata" <sujatagp@gmail.com> wrote in message <isi2us$eg6$1@newscl01ah.mathworks.com>...
> Hi
>
> I have a matrix 5 by 4 with number in it some positive some negative.
> I would like to display these in a data_table. I did so but now I want to display the numbers that are negative in red and the numbers that are positive in black (which is default).. I mean the number itself and not the background color should be in red.
>
> If I have the matrix I just use matrix < 0 to get a logical matrix to detect the negative numbers but then I get stuck translating it into the colors of a datatable inthe GUI.
>
> can anyone help mewith this.


I don't believe this can be done without bringing in some java. You would have to write a java class that implements TableCellRenderer, then you could apply it to the table using Yair's findjobj function to get the java object underlying the uitable. It's only about 5 lines of java, but still... it's java.

Subject: gui tables and colors

From: Yair Altman

Date: 7 Jun, 2011 15:24:04

Message: 4 of 4

"matt dash" wrote in message <isjj60$a7j$1@newscl01ah.mathworks.com>...
> "sujata" <sujatagp@gmail.com> wrote in message <isi2us$eg6$1@newscl01ah.mathworks.com>...
> > Hi
> >
> > I have a matrix 5 by 4 with number in it some positive some negative.
> > I would like to display these in a data_table. I did so but now I want to display the numbers that are negative in red and the numbers that are positive in black (which is default).. I mean the number itself and not the background color should be in red.
> >
> > If I have the matrix I just use matrix < 0 to get a logical matrix to detect the negative numbers but then I get stuck translating it into the colors of a datatable in the GUI.
> >
> > can anyone help me with this.
>
>
> I don't believe this can be done without bringing in some java. You would have to write a java class that implements TableCellRenderer, then you could apply it to the table using Yair's findjobj function to get the java object underlying the uitable. It's only about 5 lines of java, but still... it's java.


Yes - doing this using a dedicated Java TableCellRenderer is the best way to do it, but this requires Java.

A much simpler way is to simply use html strings within the table's data. For example: '<html><font color="red">-123' for negative (red), and regular '123' for positive (black). This relies on the fact that all Matlab GUI is based on Java Swing, which automatically accepts HTML formatting as explained here: http://UndocumentedMatlab.com/blog/html-support-in-matlab-uicomponents/

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

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.

Contact us