Posted by
simon andrews (BI) on
May 12, 2009; 8:23am
URL: http://imagej.273.s1.nabble.com/Swing-Java-components-in-ImageJ-plugin-frames-tp3692563p3692570.html
On 12 May 2009, at 09:16, Johannes Schindelin wrote:
> Hi,
>
> On Tue, 12 May 2009, Simon Andrews wrote:
>
>> On 12 May 2009, at 00:32, Johannes Schindelin wrote:
>>
>>> The problem is that you cannot add an ImageCanvas to any Swing
>>> layout.
>>
>> Sure you can. There are gotchas with mixing heavyweight (AWT) and
>> lightweight (Swing) components, but it's certainly not forbidden.
>> You
>> can add anything which derives from Component to a Swing layout,
>> which
>> covers ImageCanvas.
>
> Just that it does not display properly, defeating the purpose of the
> exercise.
That's not been my experience. It can throw off some of the dimension
calculations in swing , but these are easily worked around. The only
thing which really proved a problem was embedding AWT objects in a
JScrollPane which caused all kinds of odd display quirks.
>> Someone else posted a pointer to a list of workrounds for common
>> problems, but one other option which I've used is to create a swing
>> based version of ImageCanvas. There are very few changes required to
>> turn ImageCanvas into JImagePanel and then everything plays really
>> nicely with the rest of Swing. Probably overkill in your case, but in
>> the right situation it can be the best solution.
>
> Care to post your solution for the benefit of others (including me)?
The code is released as part of our FocalPoint viewer:
http://www.bioinformatics.bbsrc.ac.uk/projects/focalpoint/All of the image panels in the application are swing based ImageCanvas
objects. I've actually stripped out a lot of code in our released
version to keep only what we use, just to make it easier to maintain,
but when I did the original conversion I did a full swing adaption
which was surprisingly quick.
Simon.
--
Simon Andrews PhD
Babraham Bioinformatics
www.bioinformatics.bbsrc.ac.uk
[hidden email]
+44 (0) 1223 496463