f



Really really confused: Matlab's tricky window behavior on Linux, Windows 2000 and Window XP (was: why my matlab program on Linux and Windows XP behave so differently?)

"gino" <mizhael@yahoo.com> wrote in message
news:cd5a6s$due$1@news.Stanford.EDU...
> Hi folks,
>
> The matlab program is supposed to be cross platform compatible. Since
matlab
> uses Java, it should behave the same for the GUI to display on Windows XP
> and Linux. But now, the GUI window was completely random showing on Linux
> and on Windows XP. Manu UI control components are off their place. If I
fix
> this problem on Linux, the the UI controls will be off their place on
> Windows; if I fix this problem on Windows, then the UI controls will be
off
> their place on Linux.
>
> I have already set the "Units" to "character", but still there are a lot
> chaotic stuff. I am completely lost.

This may be the problem.  Looking at the documentation on the Figure
property Units, I see this:

a.. characters units are defined by characters from the default system font;
the width of one character is the width of the letter x, the height of one
character is the distance between the baselines of two lines of text.

I'm guessing your Windows and Linux machines have different system fonts,
yes?

Try setting the Units property of your GUI figure and all the components
inside it to 'normalized'.  This way you can specify that a particular
uicontrol is, say, 30% of the width of your figure away from the left side
of the figure and 20% of the height of the figure above the bottom edge.
Now no matter how your figure changes size, the uicontrol will be in the
same relative location.

> What can I do? Any work-arounds from you experienced people?
>
> I have thought of to design two GUI window seperately for windows and
Linux
> and use ISPC or COMPUTER command to distiguish the platform. But how to
let
> the GUI program to dynamically choose a GUI figure to load? Maybe I can
> first decide the platform, then change file name, say the correct GUI
> programs are:
>
> GUI.fig and GUI.m,
>
> then I just first decide the platform, then change a chosen fig file to
> GUI.fig, then it will invoke the correct GUI.fig.
>
> Just my 0.02$. not elegant at all, I know. Any thoughts?

Try the 'normalized' Units first.

> Thank you,
>
> -Gino
>
> by the way, do you happen to know why Matlab behaves so differently from
> Linux to Windows XP? Juse one example, set figure size to
>
> set(gcf, 'Position', [ScreenSize_Position])
>
> does not work on Windows XP, but works on Linux.
>
> I just don't understand why?

Make sure that the Figure and root object (0) both have their Units
properties set to the same units -- by default they are both pixels, but you
may have changed one or both of those Units properties.

-- 
Steve Lord
slord@mathworks.com

----------------------------------------------------------------
Hi Steve,

Thank you very much for your help!

For the first question, I turned all UI controls and the figure itself into
"Units" "normalized", every thing went ok on my 1280x1024 Linux box, but
when it goes to 800x600, 1024x768, 1280x960 Windows XP, now the UI controls
do not change location, but they squeeze into a small area(I guess smaller
than the one on Linux box), the text on the UIcontrols are both vertically
and horizontally cropped.

Strangely, following what was suggested by the answer by the other poster, I
tried run my GUI on different resolution on Windows 2000. It has no problem
of cropping and relocation at all.

So I really don't why it worked on Windows 2000 and Linux but not on Windows
XP? What shall I do to prevent the squeezing and cropping on Windows XP?

Regarding the second question: I made sure that the root screen and the
figure all use "Units" "Pixels", but still, on both Windows XP and Windows
2000, the figure window title, menu bar, and toolbar are out of screen when
I use the following command:

> > set(gcf, 'Position', [1, 1, ScreenWidth, ScreenHeight])

and correspondingly, the bottom part of the figure does not occupy the whole
screen(leaving some space for figure window title, menu bar and tool bar
which are shifted out of screen from the top). The same command went
perfectly on Linux.

This made me adjust the [ScreenSize_Position] parameter:

> > set(gcf, 'Position', [1, 1, ScreenWidth, ScreenHeight-71],

then on Windows 2000 it makes the maximized window covers the whole screen,
the 71 pixels means the estimated height of window title bar + menu bar +
toolbar... this solves the problem; but it is defintely not elegant. If I
can get the height of window title bar + menu bar + toolbar in advance, that
will be great!

but it did not solve the problem on Windows XP, on windows XP my
ScreenSize_Position rect reads [1, 265, 1024, 768]

very strange, right? The Y-coordinate of the screen starts at 265!

so I fixed the problem by

> > set(gcf, 'Position', [1, -265, ScreenWidth, ScreenHeight-71],

on Windows XP...



-----------------------------------

I thought I have solved this problem. But a reverse thinking terrifies me
further: I want to see what should be the correct values for figure Position
values for truely maximized figure windows, so I manually set figure windows
to maximzed, then measure the value:

The following are the values I got from my Windows XP 1152x864:

>> get(hFig1, 'Position')

ans =

           1        -263        1152         784


The following are the values I got from my Linux 1280x1024:

           1          4         1280         931

The following are the values I got from my Windows 2000 1152x864:

           1          1         1152         796

Then I change this Windows 2000 into 1280x1024:

           1         -159       1280         956

Then I close the matlab, restart matlab, then do the same thing, the
following are what I got on the same Windows 2000 1280x1024:

           1          1         1280         956

The restarting of matlab itself change the Y-coordinate value from -159 to
1, what can I say about Matlab. Why its behavior is so tricky?

Thanks a lot,

-Gino



0
mizhael (177)
7/15/2004 6:06:53 PM
comp.soft-sys.matlab 211266 articles. 15 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
2532 Views

Similar Articles

[PageSpeed] 24

"gino" <mizhael@yahoo.com> wrote in message
news:cd6h3q$9bm$1@news.Stanford.EDU...
> "gino" <mizhael@yahoo.com> wrote in message
> news:cd5a6s$due$1@news.Stanford.EDU...

*snip*

> Hi Steve,
>
> Thank you very much for your help!
>
> For the first question, I turned all UI controls and the figure itself
into
> "Units" "normalized", every thing went ok on my 1280x1024 Linux box, but
> when it goes to 800x600, 1024x768, 1280x960 Windows XP, now the UI
controls
> do not change location, but they squeeze into a small area(I guess smaller
> than the one on Linux box), the text on the UIcontrols are both vertically
> and horizontally cropped.
>
> Strangely, following what was suggested by the answer by the other poster,
I
> tried run my GUI on different resolution on Windows 2000. It has no
problem
> of cropping and relocation at all.

Do you change the resolution _while MATLAB is running_?  If so, realize that
MATLAB gets the ScreenSize property for the root object once, at startup,
and if you change the resolution after MATLAB has started, I don't believe
that change won't be propagated into the ScreenSize property until after you
restart MATLAB.

*snip*

> The following are the values I got from my Windows XP 1152x864:
>
> >> get(hFig1, 'Position')
>
> ans =
>
>            1        -263        1152         784
>
>
> The following are the values I got from my Linux 1280x1024:
>
>            1          4         1280         931
>
> The following are the values I got from my Windows 2000 1152x864:
>
>            1          1         1152         796
>
> Then I change this Windows 2000 into 1280x1024:
>
>            1         -159       1280         956
>
> Then I close the matlab, restart matlab, then do the same thing, the
> following are what I got on the same Windows 2000 1280x1024:
>
>            1          1         1280         956
>
> The restarting of matlab itself change the Y-coordinate value from -159 to
> 1, what can I say about Matlab. Why its behavior is so tricky?

This seems to point towards the cause I described above with the root
ScreenSize property.  If you want to test what effect changing resolution
will have on your GUI, change the resolution while MATLAB is closed, then
restart it and rerun your GUI.

-- 
Steve Lord
slord@mathworks.com


0
slord (13686)
7/15/2004 6:57:31 PM
"Steven Lord" <slord@mathworks.com> wrote in message
news:cd6k2r$mv4$1@fred.mathworks.com...
>
> "gino" <mizhael@yahoo.com> wrote in message
> news:cd6h3q$9bm$1@news.Stanford.EDU...
> > "gino" <mizhael@yahoo.com> wrote in message
> > news:cd5a6s$due$1@news.Stanford.EDU...
>
> *snip*
>
> > Hi Steve,
> >
> > Thank you very much for your help!
> >
> > For the first question, I turned all UI controls and the figure itself
> into
> > "Units" "normalized", every thing went ok on my 1280x1024 Linux box, but
> > when it goes to 800x600, 1024x768, 1280x960 Windows XP, now the UI
> controls
> > do not change location, but they squeeze into a small area(I guess
smaller
> > than the one on Linux box), the text on the UIcontrols are both
vertically
> > and horizontally cropped.
> >
> > Strangely, following what was suggested by the answer by the other
poster,
> I
> > tried run my GUI on different resolution on Windows 2000. It has no
> problem
> > of cropping and relocation at all.
>
> Do you change the resolution _while MATLAB is running_?  If so, realize
that
> MATLAB gets the ScreenSize property for the root object once, at startup,
> and if you change the resolution after MATLAB has started, I don't believe
> that change won't be propagated into the ScreenSize property until after
you
> restart MATLAB.
>
> *snip*
>
> > The following are the values I got from my Windows XP 1152x864:
> >
> > >> get(hFig1, 'Position')
> >
> > ans =
> >
> >            1        -263        1152         784
> >
> >
> > The following are the values I got from my Linux 1280x1024:
> >
> >            1          4         1280         931
> >
> > The following are the values I got from my Windows 2000 1152x864:
> >
> >            1          1         1152         796
> >
> > Then I change this Windows 2000 into 1280x1024:
> >
> >            1         -159       1280         956
> >
> > Then I close the matlab, restart matlab, then do the same thing, the
> > following are what I got on the same Windows 2000 1280x1024:
> >
> >            1          1         1280         956
> >
> > The restarting of matlab itself change the Y-coordinate value from -159
to
> > 1, what can I say about Matlab. Why its behavior is so tricky?
>
> This seems to point towards the cause I described above with the root
> ScreenSize property.  If you want to test what effect changing resolution
> will have on your GUI, change the resolution while MATLAB is closed, then
> restart it and rerun your GUI.
>
> -- 
> Steve Lord
> slord@mathworks.com


Hi, Steve,

Thank you for your answer. But you still did not answer me how to properly
maximized the figure window...

How do I know where do those values come from? Why 931? Why 956?



Linux 1280x1024:
> >            1          4         1280         931

Windows 2000 1280x1024:
> >            1          1         1280         956

I just want to have my figure window maximized on Linux, Windows 2000 and
Windows XP...

I thought

set(hFig, 'Position', [1, 1, 1280, 1024])

should work, but it doesnot.

What do you think?

Thank you!

-Gino




















0
mizhael (177)
7/15/2004 8:54:39 PM

"gino" <mizhael@yahoo.com> wrote in message
news:cd6qud$gdt$1@news.Stanford.EDU...
>
> "Steven Lord" <slord@mathworks.com> wrote in message
> news:cd6k2r$mv4$1@fred.mathworks.com...
> >
> > "gino" <mizhael@yahoo.com> wrote in message
> > news:cd6h3q$9bm$1@news.Stanford.EDU...
> > > "gino" <mizhael@yahoo.com> wrote in message
> > > news:cd5a6s$due$1@news.Stanford.EDU...
> >
> > *snip*
> >
> > > Hi Steve,
> > >
> > > Thank you very much for your help!
> > >
> > > For the first question, I turned all UI controls and the figure itself
> > into
> > > "Units" "normalized", every thing went ok on my 1280x1024 Linux box,
but
> > > when it goes to 800x600, 1024x768, 1280x960 Windows XP, now the UI
> > controls
> > > do not change location, but they squeeze into a small area(I guess
> smaller
> > > than the one on Linux box), the text on the UIcontrols are both
> vertically
> > > and horizontally cropped.
> > >
> > > Strangely, following what was suggested by the answer by the other
> poster,
> > I
> > > tried run my GUI on different resolution on Windows 2000. It has no
> > problem
> > > of cropping and relocation at all.
> >
> > Do you change the resolution _while MATLAB is running_?  If so, realize
> that
> > MATLAB gets the ScreenSize property for the root object once, at
startup,
> > and if you change the resolution after MATLAB has started, I don't
believe
> > that change won't be propagated into the ScreenSize property until after
> you
> > restart MATLAB.
> >
> > *snip*
> >
> > > The following are the values I got from my Windows XP 1152x864:
> > >
> > > >> get(hFig1, 'Position')
> > >
> > > ans =
> > >
> > >            1        -263        1152         784
> > >
> > >
> > > The following are the values I got from my Linux 1280x1024:
> > >
> > >            1          4         1280         931
> > >
> > > The following are the values I got from my Windows 2000 1152x864:
> > >
> > >            1          1         1152         796
> > >
> > > Then I change this Windows 2000 into 1280x1024:
> > >
> > >            1         -159       1280         956
> > >
> > > Then I close the matlab, restart matlab, then do the same thing, the
> > > following are what I got on the same Windows 2000 1280x1024:
> > >
> > >            1          1         1280         956
> > >
> > > The restarting of matlab itself change the Y-coordinate value
from -159
> to
> > > 1, what can I say about Matlab. Why its behavior is so tricky?
> >
> > This seems to point towards the cause I described above with the root
> > ScreenSize property.  If you want to test what effect changing
resolution
> > will have on your GUI, change the resolution while MATLAB is closed,
then
> > restart it and rerun your GUI.
> >
> > -- 
> > Steve Lord
> > slord@mathworks.com
>
>
> Hi, Steve,
>
> Thank you for your answer. But you still did not answer me how to properly
> maximized the figure window...
>
> How do I know where do those values come from? Why 931? Why 956?
>
>
>
> Linux 1280x1024:
> > >            1          4         1280         931
>
> Windows 2000 1280x1024:
> > >            1          1         1280         956
>
> I just want to have my figure window maximized on Linux, Windows 2000 and
> Windows XP...
>
> I thought
>
> set(hFig, 'Position', [1, 1, 1280, 1024])
>
> should work, but it doesnot.
>
> What do you think?
>
> Thank you!
>
> -Gino

Rather than trying to get the values yourself and trying to adjust them to
account for resolution changes, just make use of the root ScreenSize
property or the figure Units and Position properties.  Either of these
should get the figure to take up the screen:

set(gcf, 'Units', get(0, 'Units'), 'Position', get(0,'ScreenSize'))
set(gcf, 'Units', 'normalized', 'Position', [0 0 1 1])

That's the best you're going to be able to do without explicitly trying to
figure out how big the title bar is and adjust the position to match.  I
don't know of an easy way to determine this -- guess and check is about it.

-- 
Steve Lord
slord@mathworks.com


0
slord (13686)
7/16/2004 12:14:13 PM
"Steven Lord" <slord@mathworks.com> wrote in message
news:cd8gql$gmp$1@fred.mathworks.com...
>
>
> "gino" <mizhael@yahoo.com> wrote in message
> news:cd6qud$gdt$1@news.Stanford.EDU...
> >
> > "Steven Lord" <slord@mathworks.com> wrote in message
> > news:cd6k2r$mv4$1@fred.mathworks.com...
> > >
> > > "gino" <mizhael@yahoo.com> wrote in message
> > > news:cd6h3q$9bm$1@news.Stanford.EDU...
> > > > "gino" <mizhael@yahoo.com> wrote in message
> > > > news:cd5a6s$due$1@news.Stanford.EDU...
> > >
> > > *snip*
> > >
> > > > Hi Steve,
> > > >
> > > > Thank you very much for your help!
> > > >
> > > > For the first question, I turned all UI controls and the figure
itself
> > > into
> > > > "Units" "normalized", every thing went ok on my 1280x1024 Linux box,
> but
> > > > when it goes to 800x600, 1024x768, 1280x960 Windows XP, now the UI
> > > controls
> > > > do not change location, but they squeeze into a small area(I guess
> > smaller
> > > > than the one on Linux box), the text on the UIcontrols are both
> > vertically
> > > > and horizontally cropped.
> > > >
> > > > Strangely, following what was suggested by the answer by the other
> > poster,
> > > I
> > > > tried run my GUI on different resolution on Windows 2000. It has no
> > > problem
> > > > of cropping and relocation at all.
> > >
> > > Do you change the resolution _while MATLAB is running_?  If so,
realize
> > that
> > > MATLAB gets the ScreenSize property for the root object once, at
> startup,
> > > and if you change the resolution after MATLAB has started, I don't
> believe
> > > that change won't be propagated into the ScreenSize property until
after
> > you
> > > restart MATLAB.
> > >
> > > *snip*
> > >
> > > > The following are the values I got from my Windows XP 1152x864:
> > > >
> > > > >> get(hFig1, 'Position')
> > > >
> > > > ans =
> > > >
> > > >            1        -263        1152         784
> > > >
> > > >
> > > > The following are the values I got from my Linux 1280x1024:
> > > >
> > > >            1          4         1280         931
> > > >
> > > > The following are the values I got from my Windows 2000 1152x864:
> > > >
> > > >            1          1         1152         796
> > > >
> > > > Then I change this Windows 2000 into 1280x1024:
> > > >
> > > >            1         -159       1280         956
> > > >
> > > > Then I close the matlab, restart matlab, then do the same thing, the
> > > > following are what I got on the same Windows 2000 1280x1024:
> > > >
> > > >            1          1         1280         956
> > > >
> > > > The restarting of matlab itself change the Y-coordinate value
> from -159
> > to
> > > > 1, what can I say about Matlab. Why its behavior is so tricky?
> > >
> > > This seems to point towards the cause I described above with the root
> > > ScreenSize property.  If you want to test what effect changing
> resolution
> > > will have on your GUI, change the resolution while MATLAB is closed,
> then
> > > restart it and rerun your GUI.
> > >
> > > -- 
> > > Steve Lord
> > > slord@mathworks.com
> >
> >
> > Hi, Steve,
> >
> > Thank you for your answer. But you still did not answer me how to
properly
> > maximized the figure window...
> >
> > How do I know where do those values come from? Why 931? Why 956?
> >
> >
> >
> > Linux 1280x1024:
> > > >            1          4         1280         931
> >
> > Windows 2000 1280x1024:
> > > >            1          1         1280         956
> >
> > I just want to have my figure window maximized on Linux, Windows 2000
and
> > Windows XP...
> >
> > I thought
> >
> > set(hFig, 'Position', [1, 1, 1280, 1024])
> >
> > should work, but it doesnot.
> >
> > What do you think?
> >
> > Thank you!
> >
> > -Gino
>
> Rather than trying to get the values yourself and trying to adjust them to
> account for resolution changes, just make use of the root ScreenSize
> property or the figure Units and Position properties.  Either of these
> should get the figure to take up the screen:
>
> set(gcf, 'Units', get(0, 'Units'), 'Position', get(0,'ScreenSize'))
> set(gcf, 'Units', 'normalized', 'Position', [0 0 1 1])
>
> That's the best you're going to be able to do without explicitly trying to
> figure out how big the title bar is and adjust the position to match.  I
> don't know of an easy way to determine this -- guess and check is about
it.
>
> -- 
> Steve Lord
> slord@mathworks.com
>
>

Dear Steve,

Thank you for your help. But since you are from Mathworks, I have just tried
to bring this to your attention. The following command does not work
uniformly on Linux, Windows 2000 and Windows XP. I "suspect" that the
matlab's concept of a "figure" is not the same as a "window". If you apply
the following code:

set(gcf, 'Units', get(0, 'Units'), 'Position', get(0,'ScreenSize'))
set(gcf, 'Units', 'normalized', 'Position', [0 0 1 1])

what you will get is a figure without window title, menu bar and toolbar, I
guess those window title + menu bar + toolbar are now outside of the window
top.

maybe the matlab's concept of a "figure" is just a client region?

Why don't you have a try and it is really strange behavior...

Thanks a lot,

-Gino

p.s. this strange effect may give me an idea on how to calculate the client
region of a figure window precisely... :=)


0
mizhael (177)
7/16/2004 7:39:13 PM
Reply: