Path: news.mathworks.com!not-for-mail
From: "Thomas Benson" <t.benson@hrwallingford.co.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: uisetcolor + activeX ->figure without focus, if compiled
Date: Wed, 4 Nov 2009 19:46:02 +0000 (UTC)
Organization: HR Wallingford
Lines: 30
Message-ID: <hcsllq$2r3$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>
Reply-To: "Thomas Benson" <t.benson@hrwallingford.co.uk>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257363962 2915 172.30.248.37 (4 Nov 2009 19:46:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 19:46:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 578854
Xref: news.mathworks.com comp.soft-sys.matlab:582501


> 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