Login  Register

Re: Image J plugin window

Posted by Rasband, Wayne (NIH/NIMH) [E] on Dec 10, 2016; 9:23pm
URL: http://imagej.273.s1.nabble.com/Image-J-plugin-window-tp5017749p5017752.html

> On Dec 10, 2016, at 3:15 PM, boomer2016 <[hidden email]> wrote:
>
> Hi, I'm having trouble with a plugin for ImageJ, I want to be able to open up
> a new UI with menu's and buttons for functions. I have no idea how to create
> the new window. I've done GUI's before but when I try to run mine through
> ImageJ nothing happens. I'm new to developing with ImageJ.

Have the plugin implement the PlugIn interface and then ImageJ will call its run() method when it is launched. Here is an updated version of the plugin that implements PlugIn, displays messages in the “Log” window and does not cause ImageJ to exit when you close the window.

-wayne


import ij.IJ;
import ij.plugin.PlugIn;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ImageJ_Gui extends JFrame implements PlugIn, ActionListener {

   public void run(String arg) {
       new ImageJ_Gui().setVisible(true);
   }

    public ImageJ_Gui() {
       super("ImageJ Custom filter GUI");
       setSize(800, 600);
       setResizable(true);
       setLayout(new BorderLayout());

       JButton button1 = new JButton("FFT");
       JButton button2 = new JButton("InverseFFT");
       JButton button3 = new JButton("3d_plot");

       button1.addActionListener(this);
       button2.addActionListener(this);
       button3.addActionListener(this);

       add(button1, BorderLayout.LINE_START);
       add(button2, BorderLayout.AFTER_LINE_ENDS);
       add(button3, BorderLayout.AFTER_LAST_LINE);
   }

   public void actionPerformed(ActionEvent e) {
       String name = e.getActionCommand();
       if (name.equals("FFT")) {
           IJ.log("FFT clicked");
       } else if (name.equals("InverseFFT")) {
           IJ.log("InverseFFT clicked");
       } else if(name.equals("3d_plot")) {
           IJ.log("3d button clicked");
       } else
       {}
    }

}


> /**
> *
> * @author boomer
> */
> //import ij.IJ;
> //import ij.plugin.PlugIn;
> //import ij.*;
> ////import ij.process.*;
> //import ij.plugin.filter.PlugInFilter;
> //import java.awt.*;
> import java.awt.BorderLayout;
> import javax.swing.JFrame;
> import javax.swing.JButton;
> import java.awt.event.ActionListener;
> import java.awt.event.ActionEvent;
> //import ij.gui.*;
>
> public class imageJ_Gui extends JFrame implements ActionListener {
>
>    public static void main (String[] args){
>        new imageJ_Gui().setVisible(true);
>    }
>
>    //@SuppressWarnings("LeakingThisInConstructor")
>    public imageJ_Gui()
>    {
>        super("ImageJ Custom filter GUI");
>        setSize(800, 600);//size of window
>        setResizable(false);//if true you can resize the window
>        setDefaultCloseOperation(EXIT_ON_CLOSE);
>        setLayout(new BorderLayout());
>
>        JButton button1 = new JButton("FFT");
>        //button1.setActionCommand("click");
>        JButton button2 = new JButton("InverseFFT");
>        JButton button3 = new JButton("3d_plot");
>
>        button1.addActionListener(this);
>        button2.addActionListener(this);
>        button3.addActionListener(this);
>
>        add(button1, BorderLayout.LINE_START);
>        add(button2, BorderLayout.AFTER_LINE_ENDS);
>        add(button3, BorderLayout.AFTER_LAST_LINE);
>
>
>    }
>    @Override
>    public void actionPerformed(ActionEvent e)
>    {
>        String name = e.getActionCommand();
>
>        if(name.equals("FFT"))
>        {
>            //I want to call the methods in these blocks
>            System.out.println("FFT clicked");
>        }
>        else if(name.equals("InverseFFT"))
>        {
>            System.out.println("InverseFFT clicked");
>        }
>        else if(name.equals("3d_plot"))
>        {
>            System.out.println("3d button clicked");
>        }
>        else
>        {
>
>        }
>        //System.out.println("Button 1 clicked");
>    }
>
> }
>
> This is how far I am for my UI, but it doesn't open up the new window when I
> run the Plugin. Could anyone please advise where I am going wrong.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Image-J-plugin-window-tp5017749.html
> Sent from the ImageJ mailing list archive at Nabble.com.



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