0

I was wondering is it possible to add a window to another window? Like can you add that window, like an internal frame to another window. The reason why I am asking this is because I want the image window (which is produced by ImageJ) to be displayed in a desktop frame or window. Also how would you go about doing this. Thanks in advance.

selena
  • 151
  • 13
  • see http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html – Justin May 13 '14 at 17:53
  • I already looked at that and I have made many internal frames but the one in imageJ is a window and I have done "extend internalFrame" but I don't know how to get it to open within the desktop pane. Thanks but are there any ideas on this? because I tried adding the window to my desktop pane but I get and illegal arguments exception. – selena May 13 '14 at 18:00
  • A very similar question was asked already [here](http://stackoverflow.com/questions/23546698/imagewindow-inside-of-desktoppane-customized-gui-for-images) and [here](http://stackoverflow.com/questions/23552108/is-it-possible-to-put-image-window-into-a-desktop-pane). Since you are specifically targeting ImageJ internals (`ImageWindow` class), you might be better off asking on the [ImageJ mailing list](http://imagej.nih.gov/ij/list.html). – Jan Eglinger May 13 '14 at 18:30
  • @JanEglinger do you know in general if you can add window (internally) to another window? – selena May 13 '14 at 20:06
  • @selena You cannot. The only thing you could do would be to extract the content pane of the `JFrame` and add it to a `JInternalFrame`, but that will likely cause all sorts of problems in the case of ImageJ. The [ImageJ2](http://developer.imagej.net/) project specifically addresses this lack of separation of concerns. We started a proof of concept [MDI Swing UI](https://github.com/scijava/scijava-ui-swing/blob/scijava-ui-swing-0.1.1/src/main/java/org/scijava/ui/swing/mdi/SwingMdiUI.java), but it is unfortunately unfinished. It would be substantial effort to understand the code and complete it. – ctrueden May 14 '14 at 16:41
  • @ctrueden How would you extract the content pane of the JFrame? – selena May 14 '14 at 17:36
  • @selena http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html#getContentPane() – ctrueden May 15 '14 at 16:23
  • possible duplicate of [ImageJ opening imagePlus window as an internal frame inside a desktopPane](http://stackoverflow.com/questions/23528247/imagej-opening-imageplus-window-as-an-internal-frame-inside-a-desktoppane) – ctrueden May 15 '14 at 17:12
  • @selena OK, I added that as an answer, so you can accept and upvote. Glad it is working for you. But please consider all my cautions as well before spending too much time on this project! – ctrueden May 15 '14 at 17:19

1 Answers1

1

You can call the getContentPane() method of a JFrame, or more generally the getComponents() method of Container (e.g., in the case of java.awt.Frame or java.awt.Dialog windows) and then set it as the content pane of a JInternalFrame.

ctrueden
  • 6,751
  • 3
  • 37
  • 69
  • So I was able to get the content pane of the image window and I was able to put it in my internal frame but when you resize the original image window it resizes my internal frame image. So how would I make it so that when my internal frame window is resized it resizes the image? – selena May 15 '14 at 17:42
  • ImageJ does not normally resize its image when the window is resized. Try it with the normal ImageJ UI to see what I mean. So it won't behave that way in your custom UI either. I think you would have to do something hacky like add a `WindowListener` that sets the image zoom whenever the window is resized. See also: http://imagej.1557.x6.nabble.com/Resize-window-and-image-in-a-macro-td3698385.html – ctrueden May 15 '14 at 22:24
  • Cause I know Image Window class there is a function setLocationAndSize, where according to the description zooms the image if the frame has changed. So I think this is where the image is being able to be zoom with respect to the frame. But I tried using the function but it doesn't seem to work I don't know if I inputting the wrong parameters. – selena May 16 '14 at 15:23