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:
java slider - background color

Subject: java slider - background color

From: Jveer

Date: 1 Apr, 2009 13:09:01

Message: 1 of 4

can anyone tell me how to set the background color or java slider on matlab?

when i use 'background',[1 0 0] for e.g when creating the java control it doesnt work

i know its possible because the color can be changed interactively using 'findjobj'

Subject: java slider - background color

From: Yair Altman

Date: 2 Apr, 2009 09:16:01

Message: 2 of 4

"Jveer " <jveer@jveer.com> wrote in message <gqvp1d$4ju$1@fred.mathworks.com>...
> can anyone tell me how to set the background color or java slider on matlab?
>
> when i use 'background',[1 0 0] for e.g when creating the java control it doesnt work
>
> i know its possible because the color can be changed interactively using 'findjobj'


Java colors are a bit different than ML colors. See http://java.sun.com/javase/6/docs/api/java/awt/Color.html . Here are some examples:

set(javaObject, 'ForegroundColor',java.awt.Color.red);
set(javaObject, 'ForegroundColor',java.awt.Color(1,0,0));
set(javaObject, 'ForegroundColor',java.awt.Color(int16(255),int16(0),int16(0)));

You can also use UIINSPECT (from the File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/17935 ) to see the available alternatives:

uiinspect('java.awt.Color');

Yair Altman
http://UndocumentedMatlab.com
 

Subject: java slider - background color

From: Jveer

Date: 2 Apr, 2009 11:05:05

Message: 3 of 4

it doesnt work

i do the following:

uicomponent('style','slider', 'position',[50,50,60,150], 'value',70, ...
    'MajorTickSpacing',20, 'MinorTickSpacing',5,...
    'Paintlabels',1,'PaintTicks',1, 'Orientation',1,'MouseReleasedCallback',{@jslider1},...
    'BackgroundColor',[1 1 1]);

set(javax.swing.JSlider, 'ForegroundColor',java.awt.Color(1,0,0))

i get the following error msg:

??? Error using ==> set
Invalid property found.
Object Name : javax.swing.JSlider
Property Name : 'ForegroundColor'.

Error in ==> untitled1>pushbutton1_Callback at 96
set(javax.swing.JSlider, 'ForegroundColor',java.awt.Color(1,0,0))

Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> untitled1 at 43
    gui_mainfcn(gui_State, varargin{:});

Error in ==>
@(hObject,eventdata)untitled1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

 
??? Error while evaluating uicontrol Callback

Subject: java slider - background color

From: matt dash

Date: 2 Apr, 2009 15:09:01

Message: 4 of 4

"Jveer " <jveer@jveer.com> wrote in message <gr2651$3b$1@fred.mathworks.com>...
> it doesnt work
>
> i do the following:
>
> uicomponent('style','slider', 'position',[50,50,60,150], 'value',70, ...
> 'MajorTickSpacing',20, 'MinorTickSpacing',5,...
> 'Paintlabels',1,'PaintTicks',1, 'Orientation',1,'MouseReleasedCallback',{@jslider1},...
> 'BackgroundColor',[1 1 1]);
>
> set(javax.swing.JSlider, 'ForegroundColor',java.awt.Color(1,0,0))
>
> i get the following error msg:
>
> ??? Error using ==> set
> Invalid property found.
> Object Name : javax.swing.JSlider
> Property Name : 'ForegroundColor'.
>
> Error in ==> untitled1>pushbutton1_Callback at 96
> set(javax.swing.JSlider, 'ForegroundColor',java.awt.Color(1,0,0))
>
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
>
> Error in ==> untitled1 at 43
> gui_mainfcn(gui_State, varargin{:});
>
> Error in ==>
> @(hObject,eventdata)untitled1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
>
>
> ??? Error while evaluating uicontrol Callback

I believe the property is called "foreground" not "foregroundcolor", but for me (default windows xp l&f) it doesnt actually affect anything, only the background color matters.

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