Hello Everyone
Is it possible to display the ImagePlus window inside Jframe. I couldnt find out a way of displaying it in such away that it can even be cropped from there. So far i am display the buffered image inside the frame but when i have to crop the image i have to open it up again in imageJ window. Thanks in advance Ahsan |
You can place an ImageCanvas inside a JFrame, but you'll loose ImageJ functionality:
public static void main(String args[]) { String file = "path-to-file"; ImagePlus imp = IJ.openImage(file); ImageCanvas ic = new ImageCanvas(imp); JFrame frame = new JFrame("TEST"); frame.add(ic); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } Why do you want to use a JFrame? On Aug 9, 2011, at 11:10 AM, ashamim wrote: > Hello Everyone > > Is it possible to display the ImagePlus window inside Jframe. I couldnt find > out a way of displaying it in such away that it can even be cropped from > there. So far i am display the buffered image inside the frame but when i > have to crop the image i have to open it up again in imageJ window. > > Thanks in advance > > Ahsan > > ----- > Ahsan > -- > View this message in context: http://imagej.588099.n2.nabble.com/ImagePlus-Window-inside-JFrame-tp6667443p6667443.html > Sent from the ImageJ mailing list archive at Nabble.com. ------------------------------------------------------------ Juanjo Vega ([hidden email]) Unidad de Biocomputación. Laboratorio B-13. Centro Nacional de Biotecnología. CNB-CSIC. C\ Darwin, 3. Campus de Cantoblanco. Universidad Autónoma de Madrid. 28049, Madrid, Spain. http://www.cnb.csic.es http://www.biocomp.cnb.csic.es +34 91 585 4510 "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes. |
Juanjo
Thanks for the reply. I am implementing user interface for one plugin. One requirement is that the user might have to crop some part of the image before analysing it. I was wondering it would be better if I could display the image within the frame of UI and the user be able to crop it in there rather than in a seperate window. Regards Ahsan |
Ahsan,
I have implemented user interfaces like those, and my recommendation is to use/extend the ImageWindow class. So you can add stuff to the ImagePlus window while keeping the normal use of it. As ImageWindow is AWT, you might experiment some problems if you use SWING components. I try to stay in AWT whenever it's possible, but if not (once I needed to use a JTabbedPane), try to place your swing components in a Panel, and then add that panel to the imagewindow. I have adapted the following code from one of my recent plugins (where users had to select an area, and after that, a point inside the sub-image). Try it, and feel free to use it if you like this "style". public class CropTest { public static void main(String args[]) { new ImageJ(); IJ.run("Clown (14K)"); JFrame frame = new JFrame("Crop TEST"); JButton button = new JButton("Crop"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { crop(); } }); frame.add(button); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } private static void crop() { final ImagePlus imp = WindowManager.getCurrentImage(); if (imp != null) { final Roi roi = imp.getRoi(); if (roi != null) { if (roi.isArea()) { // Gets CenterOfMass from image ROI final ImagePlus subImp = new ImagePlus("selected region", imp.getProcessor().crop()); subImp.copyScale(imp); // Copies calibration info: pixels size, etc. // Adds a button to store points. Button bOk = new Button("Close"); bOk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { subImp.close(); } }); // Creates a new window as it will be null until "show()", ImageWindow window = new ImageWindow(subImp); // Adds button. window.add(bOk); window.pack(); subImp.show(); } else { IJ.error("ROI is not an area."); } } else { IJ.error("No ROI selected."); } } else { IJ.error("There are no images open."); } } } On Aug 9, 2011, at 12:45 PM, ashamim wrote: > Juanjo > > Thanks for the reply. I am implementing user interface for one plugin. One > requirement is that the user might have to crop some part of the image > before analysing it. I was wondering it would be better if I could display > the image within the frame of UI and the user be able to crop it in there > rather than in a seperate window. > > > Regards > > Ahsan > > ----- > Ahsan > -- > View this message in context: http://imagej.588099.n2.nabble.com/ImagePlus-Window-inside-JFrame-tp6667443p6667646.html > Sent from the ImageJ mailing list archive at Nabble.com. ------------------------------------------------------------ Juanjo Vega ([hidden email]) Unidad de Biocomputación. Laboratorio B-13. Centro Nacional de Biotecnología. CNB-CSIC. C\ Darwin, 3. Campus de Cantoblanco. Universidad Autónoma de Madrid. 28049, Madrid, Spain. http://www.cnb.csic.es http://www.biocomp.cnb.csic.es +34 91 585 4510 "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes. |
In reply to this post by ashamim
Juanjo
Thanks alot for the reply . You are right and I guess this would work fine for me. I'll just try this and come back to you incase if i have any problem. Thanks again. |
Free forum by Nabble | Edit this page |