Login  Register

Re: Attempting to modify the ImageJ user interface to create a "mini application"

Posted by Peterbauer Thomas on Jan 21, 2019; 7:46pm
URL: http://imagej.273.s1.nabble.com/Attempting-to-modify-the-ImageJ-user-interface-to-create-a-mini-application-tp5021669p5021678.html

On 21.01.19 19:12, Grayson Harrington wrote:
> and the main ImageJ window is still visible. Has anyone seen this before or
> does anyone know about it?

It depends how far you want to take all this, but a cleaner solution
would be to revert the hierarchy: rather than running your plugin under
ImageJ, run ImageJ as library in your own app. The following class loads
ImageJ and makes it available for image processing without ever showing
the ImageJ window:

import ij.IJ;
import ij.ImageJ;
import ij.ImagePlus;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MyApp extends JFrame {

     private ImageJ ij;

     public MyApp() {
         super("My Application");
         this.ij = new ImageJ(ImageJ.NO_SHOW);
         setSize(300, 300);
         setLocationRelativeTo(null);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         addWindowListener(new WindowAdapter() {

             @Override
             public void windowClosing(WindowEvent e) {
                 ij.quit();
                 super.windowClosing(e);
             }
         });
         JButton button = new JButton("Open Image...");
         button.addActionListener(new ActionListener() {

             @Override
             public void actionPerformed(ActionEvent e) {
                 ImagePlus imp = IJ.openImage();
                 imp.show();
             }
         });
         JPanel contentPane = new JPanel(new BorderLayout());
         getContentPane().add(contentPane);
         contentPane.add(button, BorderLayout.NORTH);
         setVisible(true);
     }

     public static void main(String[] args) {
         new MyApp();
     }
}



--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html