Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: uisetcolor + activeX ->figure without focus, if compiled
Date: Wed, 4 Nov 2009 22:48:02 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 39
Message-ID: <hct0b2$9jq$1@fred.mathworks.com>
References: <gpdqsp$29p$1@fred.mathworks.com> <gtphhd$ggg$1@fred.mathworks.com> <h61v4h$hgj$1@fred.mathworks.com> <h6gbut$mco$1@fred.mathworks.com> <h6gck2$59g$1@fred.mathworks.com> <h6h023$lj$1@fred.mathworks.com> <h6h4co$leh$1@fred.mathworks.com> <hcritt$113$1@fred.mathworks.com> <hcrviv$9uo$1@fred.mathworks.com> <hcsllq$2r3$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257374882 9850 172.30.248.35 (4 Nov 2009 22:48:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 22:48:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: news.mathworks.com comp.soft-sys.matlab:582552


"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