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:
how to set properties of java uicontrols

Subject: how to set properties of java uicontrols

From: Ramiro Massol

Date: 16 Jan, 2010 21:24:05

Message: 1 of 6

i'm trying to use some java uicontrols (jslider, jprogressbar) but i don't know how to set their properties.
For example, I would like to change the font type and size of a jslider and so far i've got to this:
figure
h = uicomponent('style','slider', 'position',[150,50,180,50], 'value',70, ...
    'MajorTickSpacing',20, 'MinorTickSpacing',5, ...
    'Paintlabels',1,'PaintTicks',1, 'Orientation',0);
jSlider = findjobj(h,'nomenu');
jSlider.setFont('Comic Sans MS', 'PLAIN', 28)


but the jslider font remains unchanged.

please help!

best

Subject: how to set properties of java uicontrols

From: Yair Altman

Date: 16 Jan, 2010 23:04:03

Message: 2 of 6

"Ramiro Massol" <ramiro.massol@childrens.harvard.edu> wrote in message <hitapk$o58$1@fred.mathworks.com>...
> i'm trying to use some java uicontrols (jslider, jprogressbar) but i don't know how to set their properties.
> For example, I would like to change the font type and size of a jslider and so far i've got to this:
> figure
> h = uicomponent('style','slider', 'position',[150,50,180,50], 'value',70, ...
> 'MajorTickSpacing',20, 'MinorTickSpacing',5, ...
> 'Paintlabels',1,'PaintTicks',1, 'Orientation',0);
> jSlider = findjobj(h,'nomenu');
> jSlider.setFont('Comic Sans MS', 'PLAIN', 28)
>
>
> but the jslider font remains unchanged.
>
> please help!
>
> best

Hi again Ramiro :-)

You were nearly correct in your syntax - the correct version is:
jSlider.setFont(java.awt.Font('Comic Sans MS',java.awt.Font.PLAIN,28))

Also, there is no need to use findjobj() to get the Java handle - it is already returned by uicomponent() as a field of the returned handle:

h = uicomponent('style','slider',...);
jSlider = h.JavaComponent;

Yair Altman
http://UndocumentedMatlab.com

Subject: how to set properties of java uicontrols

From: Ramiro Massol

Date: 17 Jan, 2010 13:07:03

Message: 3 of 6

thanks Yair for your help! You mentioned that uicomponent provides also the java handle for the component, how is this? the handle obtained after :
h = uicomponent(......

is a matlab handle.

another question. how do you control the appearance of the track/cursor of jslider? how to set the step of the jslider to go one unit per click and not to jump so much?

by the way, i'll write to you soon about our jtable project for an upgrade.

best

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hitgl3$2ga$1@fred.mathworks.com>...
> "Ramiro Massol" <ramiro.massol@childrens.harvard.edu> wrote in message <hitapk$o58$1@fred.mathworks.com>...
> > i'm trying to use some java uicontrols (jslider, jprogressbar) but i don't know how to set their properties.
> > For example, I would like to change the font type and size of a jslider and so far i've got to this:
> > figure
> > h = uicomponent('style','slider', 'position',[150,50,180,50], 'value',70, ...
> > 'MajorTickSpacing',20, 'MinorTickSpacing',5, ...
> > 'Paintlabels',1,'PaintTicks',1, 'Orientation',0);
> > jSlider = findjobj(h,'nomenu');
> > jSlider.setFont('Comic Sans MS', 'PLAIN', 28)
> >
> >
> > but the jslider font remains unchanged.
> >
> > please help!
> >
> > best
>
> Hi again Ramiro :-)
>
> You were nearly correct in your syntax - the correct version is:
> jSlider.setFont(java.awt.Font('Comic Sans MS',java.awt.Font.PLAIN,28))
>
> Also, there is no need to use findjobj() to get the Java handle - it is already returned by uicomponent() as a field of the returned handle:
>
> h = uicomponent('style','slider',...);
> jSlider = h.JavaComponent;
>
> Yair Altman
> http://UndocumentedMatlab.com

Subject: how to set properties of java uicontrols

From: Yair Altman

Date: 17 Jan, 2010 16:19:04

Message: 4 of 6

"Ramiro Massol" <ramiro.massol@childrens.harvard.edu> wrote in message...
> thanks Yair for your help! You mentioned that uicomponent provides also the java handle for the component, how is this? the handle obtained after :
> h = uicomponent(......
> is a matlab handle.

uicomponent attaches the JavaComponent property to the h handle using the undocumented schema.prop function. Take a look within the uicomponent.m source code, which is pretty-well documented.

> another question. how do you control the appearance of the track/cursor of jslider? how to set the step of the jslider to go one unit per click and not to jump so much?

JSlider has a variety of properties that you can set to customize its appearance and behavior. Type set(jslider) or get(jslider) or inspect(jslider) to see the list of properties. You can also use a variety of built-in methods and callbacks - use my UIInspect utility from the File Exchange to see them. Here's the official documentation:

http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html
http://java.sun.com/javase/6/docs/api/javax/swing/JSlider.html

Yair Altman
http://UndocumentedMatlab.com

Subject: how to set properties of java uicontrols

From: Ramiro Massol

Date: 17 Jan, 2010 21:53:03

Message: 5 of 6

thanks for the tips. I now can set some properties but i'm still at odds about the default behavior of jslider. For instance, it only calls my callback after the mouse is released and not during dragging. I checked everywhere and you mentioned in a previous post that there is a method called 'AdjustmentValueChangedCallback ' to allow the detection of the movement of the slider. I cannot see this method in my jslider callback or methods. How can i set a callback associated to dragging the cursor of the slider?

best
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hivd9o$bo9$1@fred.mathworks.com>...
> "Ramiro Massol" <ramiro.massol@childrens.harvard.edu> wrote in message...
> > thanks Yair for your help! You mentioned that uicomponent provides also the java handle for the component, how is this? the handle obtained after :
> > h = uicomponent(......
> > is a matlab handle.
>
> uicomponent attaches the JavaComponent property to the h handle using the undocumented schema.prop function. Take a look within the uicomponent.m source code, which is pretty-well documented.
>
> > another question. how do you control the appearance of the track/cursor of jslider? how to set the step of the jslider to go one unit per click and not to jump so much?
>
> JSlider has a variety of properties that you can set to customize its appearance and behavior. Type set(jslider) or get(jslider) or inspect(jslider) to see the list of properties. You can also use a variety of built-in methods and callbacks - use my UIInspect utility from the File Exchange to see them. Here's the official documentation:
>
> http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html
> http://java.sun.com/javase/6/docs/api/javax/swing/JSlider.html
>
> Yair Altman
> http://UndocumentedMatlab.com

Subject: how to set properties of java uicontrols

From: Yair Altman

Date: 17 Jan, 2010 22:29:05

Message: 6 of 6

"Ramiro Massol" <ramiro.massol@childrens.harvard.edu> wrote in message <hj00rv$cna$1@fred.mathworks.com>...
> thanks for the tips. I now can set some properties but i'm still at odds about the default behavior of jslider. For instance, it only calls my callback after the mouse is released and not during dragging. I checked everywhere and you mentioned in a previous post that there is a method called 'AdjustmentValueChangedCallback ' to allow the detection of the movement of the slider. I cannot see this method in my jslider callback or methods. How can i set a callback associated to dragging the cursor of the slider?


'AdjustmentValueChangedCallback' is a scrollbar property. The corresponding slider property is 'StateChangedCallback'.

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