Thread Subject: uisetcolor + activeX ->figure without focus, if compiled

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Andreas Greuer

Date: 13 Mar, 2009 14:34:01

Message: 1 of 13

Hallo,

I'm using uisetcolor in combination with an activeX.
If my application is compiled, I'm loosing the focus of the figure and can't get it back, after using the uisetcolor command.

The following code works fine, if not compiled.
I compile with the Compiler version: 4.10 (R2009a):
mcc -mv test3.m

In the example I use the MS Excel Spreadsheet. But I had the same effect using another ActiveX.

Has somebody experienced something like this?

Andreas
----------------------------
function test
f=figure;
 uicontrol('Parent',f,'Style', 'pushbutton',...
    'Position', [0 0 130 30],'String','Color',...
    'CallBack',@color_Callback);
actxcontrol('OWC.Spreadsheet.9', [150 150 300 300],f);
return

function color_Callback(hObject, eventdata, handles)
  c1=get(gcf,'Color');
  c = uisetcolor(c1, 'Entity color');
  disp('HALLO') ;
  if sum(c1==c)<3
    set(gcf,'Color',c);
  end
return

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Yair Altman

Date: 13 Mar, 2009 14:54:01

Message: 2 of 13

> I'm using uisetcolor in combination with an activeX.
> If my application is compiled, I'm loosing the focus of the figure and can't get it back, after using the uisetcolor command.
[snip]
> f=figure;
> uicontrol('Parent',f,'Style', 'pushbutton',...
> 'Position', [0 0 130 30],'String','Color',...
> 'CallBack',@color_Callback);

You can use figure(f) to programmatically regain figure focus, or uicontrol(h) to set the focus to a specific uicontrol handle (which you should get from the initial uicontrol invocation). I believe that the latter option (uicontrol(h)) is not documented in uicontrol's help section but it is documented in the detailed doc.

Yair Altman

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Andreas Greuer

Date: 13 Mar, 2009 16:33:01

Message: 3 of 13

> You can use figure(f) to programmatically regain figure focus, or uicontrol(h) to set the focus to a specific uicontrol handle (which you should get from the initial uicontrol invocation). I believe that the latter option (uicontrol(h)) is not documented in uicontrol's help section but it is documented in the detailed doc.
>
I put the command in my testapplication and indeed the focus switchs from
the command window back to the figure.
But I can access the figure. I can't press the button or close, minimize or maximize the figure.

Andreas

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Corbin Holland

Date: 5 May, 2009 14:13:01

Message: 4 of 13

I am having the same problem. I just compiled my app and the uisetcolor call is causing havoc on the program. I think it is getting stuck in "modal" mode. After you hit "Ok" or "Cancel" the dialog disappears but it seems as if the program still thinks the "modal" dialog is still on the screen so it won't let you click on anything at all. Anyone have a solution for this? Note this works fine in matlab its just the compiled version that is messed up.

I am using 2009a on XP btw...

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Kevin

Date: 13 Aug, 2009 21:04:17

Message: 5 of 13

I had the same problem, but callling uicontrol(h) after the uisetcolor command solved it. Many thanks for the idea. (Running R2008b under XP).

Kevin

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Andreas Greuer

Date: 19 Aug, 2009 08:09:02

Message: 6 of 13

This did not solve the problem. In the compiled version I still don't get back the focus. - Matlab Compiler 4.10 (R2009a)
Compile the following program (mcc -mv test.m). No matter you press ok or cancel in the colordialog, the program will crash in the compiled version. The not compiled version works fine.
----------------------
function test
f=figure;
 uicontrol('Parent',f,'Style', 'pushbutton',...
    'Position', [0 0 130 30],'String','Color',...
    'CallBack',@color_Callback);
actxcontrol('OWC.Spreadsheet.9', [150 150 300 300],f);
return

function color_Callback(hObject, eventdata, handles)
  c1=get(gcf,'Color');
  c = uisetcolor(c1, 'Entity color');
  uicontrol(hObject);
  disp('HALLO') ;
  if sum(c1==c)<3
    set(gcf,'Color',c);
  end
return

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Andreas Greuer

Date: 19 Aug, 2009 08:20:18

Message: 7 of 13

Just compiled the application with the old compiler version 4.6 (R2007a). And there it works fine.
-> So it seems to be a problem of the new compiler version 4.10 (R2009a)

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Corbin Holland

Date: 19 Aug, 2009 13:52:03

Message: 8 of 13

"Andreas Greuer" <greuer@remove-this-gmx.de> wrote in message <h6gck2$59g$1@fred.mathworks.com>...
> Just compiled the application with the old compiler version 4.6 (R2007a). And there it works fine.
> -> So it seems to be a problem of the new compiler version 4.10 (R2009a)

I ran into the same problem a few months back. I solved it by adding a tiny pause after the uisetcolor call. I just wrapped the uisetcolor call and added a slight delay like this:

function newcolor = colorChooser( varargin )

% This is just a wrapper for the uisetcolor function. I made it so I could add the pause to account
% for a bug in the compiled version for 2009a.

newcolor = uisetcolor(varargin{:});

if (isdeployed)
   pause(.1); % necessary for compiled version 2009a or the dialog disappears but prog thinks modal is active
              % and you can no longer click on anything at all
end


let me know if any of you come up with a better solution.

- Corbin

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: matt dash

Date: 19 Aug, 2009 15:06:01

Message: 9 of 13

"Corbin Holland" <cholland.nospam@opticalsciences.com> wrote in message <h6h023$lj$1@fred.mathworks.com>...
> "Andreas Greuer" <greuer@remove-this-gmx.de> wrote in message <h6gck2$59g$1@fred.mathworks.com>...
> > Just compiled the application with the old compiler version 4.6 (R2007a). And there it works fine.
> > -> So it seems to be a problem of the new compiler version 4.10 (R2009a)
>
> I ran into the same problem a few months back. I solved it by adding a tiny pause after the uisetcolor call. I just wrapped the uisetcolor call and added a slight delay like this:
>
> function newcolor = colorChooser( varargin )
>
> % This is just a wrapper for the uisetcolor function. I made it so I could add the pause to account
> % for a bug in the compiled version for 2009a.
>
> newcolor = uisetcolor(varargin{:});
>
> if (isdeployed)
> pause(.1); % necessary for compiled version 2009a or the dialog disappears but prog thinks modal is active
> % and you can no longer click on anything at all
> end
>
>
> let me know if any of you come up with a better solution.
>
> - Corbin


Not sure if it will make a difference, but you could try using a JColorChooser instead of uisetcolor. See the demo file in my file "rgb2name" on the file exchange for an example of how it works.

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Thomas Benson

Date: 4 Nov, 2009 09:53:01

Message: 10 of 13

"matt dash" <n.a@mail.com> wrote in message <h6h4co$leh$1@fred.mathworks.com>...
> "Corbin Holland" <cholland.nospam@opticalsciences.com> wrote in message <h6h023$lj$1@fred.mathworks.com>...
> > "Andreas Greuer" <greuer@remove-this-gmx.de> wrote in message <h6gck2$59g$1@fred.mathworks.com>...
> > > Just compiled the application with the old compiler version 4.6 (R2007a). And there it works fine.
> > > -> So it seems to be a problem of the new compiler version 4.10 (R2009a)
> >
> > I ran into the same problem a few months back. I solved it by adding a tiny pause after the uisetcolor call. I just wrapped the uisetcolor call and added a slight delay like this:
> >
> > function newcolor = colorChooser( varargin )
> >
> > % This is just a wrapper for the uisetcolor function. I made it so I could add the pause to account
> > % for a bug in the compiled version for 2009a.
> >
> > newcolor = uisetcolor(varargin{:});
> >
> > if (isdeployed)
> > pause(.1); % necessary for compiled version 2009a or the dialog disappears but prog thinks modal is active
> > % and you can no longer click on anything at all
> > end
> >
> >
> > let me know if any of you come up with a better solution.
> >
> > - Corbin
>
>
> Not sure if it will make a difference, but you could try using a JColorChooser instead of uisetcolor. See the demo file in my file "rgb2name" on the file exchange for an example of how it works.

Matt,

Thanks for this excellent suggestion. It looks like it solves a similar problem I am having with uisetcolor freezing the main figure in a compiled program (compiled using compiler V79 that is shipped with R2008b). Do you know how to get the JColorChooser to initialise with a colour other than white? (i.e. I want it to start with the colour that is already assigned to a uicontrol).

Thanks in advance
Thomas

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Yair Altman

Date: 4 Nov, 2009 13:29:03

Message: 11 of 13

> > Not sure if it will make a difference, but you could try using a JColorChooser instead of uisetcolor. See the demo file in my file "rgb2name" on the file exchange for an example of how it works.
>
> Matt,
>
> Thanks for this excellent suggestion. It looks like it solves a similar problem I am having with uisetcolor freezing the main figure in a compiled program (compiled using compiler V79 that is shipped with R2008b). Do you know how to get the JColorChooser to initialise with a colour other than white? (i.e. I want it to start with the colour that is already assigned to a uicontrol).
>
> Thanks in advance
> Thomas


You can pass a Java Color object to JColorChooser upon construction. For example:

hColor = get(hControl,'BackgroundColor');
cColor = mat2cell(hcolor,1,[1,1,1]); % convert to cell array
jColor = java.awt.Color(cColor{:}); % convert to Java Color object
jObject = JColorChooser(jColor); % prepare the JColorChooser etc.

More info:
http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html
http://java.sun.com/docs/books/tutorial/uiswing/components/colorchooser.html

Yair Altman
http://undocumentedMatlab.com

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Thomas Benson

Date: 4 Nov, 2009 19:46:02

Message: 12 of 13

> You can pass a Java Color object to JColorChooser upon construction. For example:
>
> hColor = get(hControl,'BackgroundColor');
> cColor = mat2cell(hcolor,1,[1,1,1]); % convert to cell array
> jColor = java.awt.Color(cColor{:}); % convert to Java Color object
> jObject = JColorChooser(jColor); % prepare the JColorChooser etc.
>
> More info:
> http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html
> http://java.sun.com/docs/books/tutorial/uiswing/components/colorchooser.html
>
> Yair Altman
> http://undocumentedMatlab.com

Thanks so much for the reply. It has proved to be very useful for a non-java bloke like me. It has completely solved my problem now. Below is part of the final code which starts up the JColorChooser with purple as the initial colour:

% define an initial colour
initialColor = [0.5 0 1];

% create the java colour chooser
figure('units','pixels','position',[200 200 430 386],'menubar','none');
[j h]=javacomponent('javax.swing.JColorChooser',[0 36 430 350]);

% set the colour to the initial colour
cColor = mat2cell(initialColor,1,[1,1,1]); % convert to cell array
jColor = java.awt.Color(cColor{:}); % convert to Java Color object
set(j,'Color',jColor)

-----
Thomas Benson

Subject: uisetcolor + activeX ->figure without focus, if compiled

From: Yair Altman

Date: 4 Nov, 2009 22:48:02

Message: 13 of 13

"Thomas Benson" <t.benson@hrwallingford.co.uk> wrote in message <hcsllq$2r3$1@fred.mathworks.com>...
> > You can pass a Java Color object to JColorChooser upon construction. For example:
> >
> > hColor = get(hControl,'BackgroundColor');
> > cColor = mat2cell(hcolor,1,[1,1,1]); % convert to cell array
> > jColor = java.awt.Color(cColor{:}); % convert to Java Color object
> > jObject = JColorChooser(jColor); % prepare the JColorChooser etc.
> >
> > More info:
> > http://java.sun.com/javase/6/docs/api/javax/swing/JColorChooser.html
> > http://java.sun.com/docs/books/tutorial/uiswing/components/colorchooser.html
> >
> > Yair Altman
> > http://undocumentedMatlab.com
>
> Thanks so much for the reply. It has proved to be very useful for a non-java bloke like me. It has completely solved my problem now. Below is part of the final code which starts up the JColorChooser with purple as the initial colour:
>
> % define an initial colour
> initialColor = [0.5 0 1];
>
> % create the java colour chooser
> figure('units','pixels','position',[200 200 430 386],'menubar','none');
> [j h]=javacomponent('javax.swing.JColorChooser',[0 36 430 350]);
>
> % set the colour to the initial colour
> cColor = mat2cell(initialColor,1,[1,1,1]); % convert to cell array
> jColor = java.awt.Color(cColor{:}); % convert to Java Color object
> set(j,'Color',jColor)
>
> -----
> Thomas Benson


Note that there are several ways in which you can define Java colors:
java.awt.Color(0.5,0,1); % =purple, equivalent to Color(cColor{:}) above
java.awt.Color(int16(128),0,int16(255)); % =purple
java.awt.Color.red % the major colors are pre-defined (unfortunately not purple)

Yair

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
colorchooser ui... Corbin Holland 19 Aug, 2009 09:54:03
uicontrol Kevin 13 Aug, 2009 17:09:04
compiled Kevin 13 Aug, 2009 17:09:04
modal Kevin 13 Aug, 2009 17:09:04
uisetcolor Kevin 13 Aug, 2009 17:09:04
undocumented Yair Altman 13 Mar, 2009 10:55:11
focus Andreas Greuer 13 Mar, 2009 10:35:07
modal Andreas Greuer 13 Mar, 2009 10:35:07
compiler Andreas Greuer 13 Mar, 2009 10:35:07
ocx Andreas Greuer 13 Mar, 2009 10:35:07
activex Andreas Greuer 13 Mar, 2009 10:35:07
uisetcolor Andreas Greuer 13 Mar, 2009 10:35:07
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