Login  Register

Re: question about adding component to a ImageWindow

Posted by ctrueden on Oct 07, 2008; 6:09pm
URL: http://imagej.273.s1.nabble.com/question-about-adding-component-to-a-ImageWindow-tp3694834p3694838.html

Hi Xin & Patrick,

Actually, you can use Swing inside of a heavyweight AWT window in most
circumstances -- there are just a couple of gotchas. For an example of
extending StackWindow (which extends ImageWindow) with additional
components, as well as mixing in Swing, check out LOCI's Data Browser
plugin:

https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/src/loci/plugins/DataBrowser.java

For more about mixing AWT and Swing, see this ancient (but still relevant)
article from Sun:

http://java.sun.com/products/jfc/tsc/articles/mixing/

Cheers,
Curtis

On Tue, Oct 7, 2008 at 10:31 AM, Patrick Pirrotte <
[hidden email]> wrote:

> Hi Xin,
>
> Did you extend ImageCanvas as described in Panel_Window example?
> (http://rsb.info.nih.gov/ij/plugins/download/Panel_Window.java)
>
> As TextPanel is a subclass of java.awt.Panel, adding a panel should be no
> problem...
>
> ....
>
>  void addPanel() {
>            add(new TextPanel("Title"));
>            pack();
>        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
>            Point loc = getLocation();
>            Dimension size = getSize();
>            if (loc.y+size.height>screen.height)
>                getCanvas().zoomOut(0, 0);
>         }
> ....
>
> Regards,
>
> Patrick
>
> -----Original Message-----
> From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of xin
> zhang
> Sent: 07 October 2008 16:41
> To: [hidden email]
> Subject: Re: question about adding component to a ImageWindow
>
> Hi, Patrick,
>
> Thanks for the information, what I tried to put in the ImageWindow was
> actually an object of ij.text.TextPanel.
>
> So, any idea?
>
> Xin
>
> On Tue, Oct 7, 2008 at 3:27 AM, Patrick Pirrotte
> <[hidden email]> wrote:
> > Hi Xin,
> >
> > If you want to extend ImageWindow or ImageCanvas you need to stay in AWT.
> > Try replacing JTextPane by java.awt.TextArea.
> >
> > You can't mix heavyweight components (such as AWT) with lightweight
> > components (such as Swing). As ImageJ is written in AWT, inside Frames
> > such as ImageWindow/ImageCanvas only AWT components get correctly
> > drawn. You can put Swing components into a separate JFrame though, and
> > several plugins do so to profit from the larger component library offered
> by javax.swing.*.
> >
> > Regards,
> >
> > Patrick
> >
> > -----Original Message-----
> > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of
> > xin zhang
> > Sent: 07 October 2008 00:03
> > To: [hidden email]
> > Subject: question about adding component to a ImageWindow
> >
> > Hi,
> >
> > I am trying to add a TextPanel to an ImageWindow, however, no matter
> > how do I set the size of the TextPanel, I always get tiny TextPanel as
> > shown at
> > http://terpconnect.umd.edu/~zhangx/imagej/nanoscopeiiireader/Picture-2<http://terpconnect.umd.edu/%7Ezhangx/imagej/nanoscopeiiireader/Picture-2>
> > .png
> >
> > Has anybody any idea how to make the TextPanel take the whole width of
> > the window?
> >
> > Thanks in advance.
> >
> > Xin
> >
> > --
> > ***********************************************
> > Xin Zhang
> > Graduate Student
> > Department of Materials Science and Engineering University of Maryland
> > at College Park
> > Tel: (301)405-0900
> > Email: [hidden email], [hidden email]
> > Web:http://www.glue.umd.edu/~zhangx/<http://www.glue.umd.edu/%7Ezhangx/>
> > ***********************************************
> >
>
>
>
> --
> ***********************************************
> Xin Zhang
> Graduate Student
> Department of Materials Science and Engineering University of Maryland at
> College Park
> Tel: (301)405-0900
> Email: [hidden email], [hidden email]
> Web:http://www.glue.umd.edu/~zhangx/ <http://www.glue.umd.edu/%7Ezhangx/>
> ***********************************************
>