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.
/** * * @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. |
On 2016-12-10 21:15, boomer2016 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. Let your plugin extend ij.plugin.frame.PlugInFrame. This will construct and show a java.awt.Frame. If you want a javax.swing.JFrame, you can implement the ij.plugin.PlugIn interface and construct it in the run() method. The JFrame will, however, not pop up in IJ's "Window" menu. You have to register it at the WindowManager on your own (and de-register it on closing); for frames extending PlugInFrame, all this and proper numbering of more than one instance is done by the PlugInFrame superclass. Best, Thomas -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you for the help.
|
In reply to this post by boomer2016
> 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 |
thank you Wayne.
|
Free forum by Nabble | Edit this page |