Login  Register

Re: Running Java based GUIs as Plug In

Posted by John Hayes on Oct 14, 2013; 1:57pm
URL: http://imagej.273.s1.nabble.com/Running-Java-based-GUIs-as-Plug-In-tp5005165p5005179.html

Hi Steve,

ImageJ plugins don’t use the standard Java ‘main’ function as an entry point. Try creating a new ImageJ Plugin from « Plugins|New|Plugin » and calling your GUI code from within the provided « run » function. Something like the following:

> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import java.awt.image.*;
> import java.awt.event.*;
> import ij.plugin.*;
> import ij.plugin.frame.*;
> import java.awt.Color;
> import javax.swing.*;
>
> public class My_Plugin implements PlugIn {
>
> public void run(String arg) {
> IJ.showMessage("My_Plugin","Hello world!");
> JFrame myJFrame = new JFrame();
> myJFrame.setTitle("JRadioButton Beispiel");
> myJFrame.setSize(450,300);
> JPanel panel = new JPanel();
> panel.setBackground(Color.red);
>
> JCheckBox check = new JCheckBox("Ich bin eine CheckBox", true);
> panel.add(check);
>
> myJFrame.add(panel);
> myJFrame.setLocation(100, 200);
> myJFrame.pack();
> myJFrame.setVisible(true);
> }
> }
Then, compile and run...

Best regards,

John

Le 14 oct. 2013 à 15:41, Influenza a écrit :

> Hello Everyone!
>
> I'm trying to build a user-friendly GUI for a PlugIn. I know that it must be
> possible, but I looked all over the net and couldn't find a solute answer.
> The problem that I have is that the PlugIn runs bug-free, and the imageJ
> status line says "done" without showing the GUI.
>
> For example an easy code:
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import java.awt.image.*;
> import java.awt.event.*;
> import ij.plugin.*;
> import ij.plugin.frame.*;
> import java.awt.Color;
> import javax.swing.*;
>
>
>
>
> public class JFrameExample_
> {
>    public static void main(String[] args)
>    {
>
>        JFrame myJFrame = new JFrame();
>        myJFrame.setTitle("JRadioButton Beispiel");
>        myJFrame.setSize(450,300);
>        JPanel panel = new JPanel();
>        panel.setBackground(Color.red);
>
>        JCheckBox check = new JCheckBox("Ich bin eine CheckBox", true);
>        panel.add(check);
>
>        myJFrame.add(panel);
>    myJFrame.setLocation(100, 200);
> myJFrame.pack();
>        myJFrame.setVisible(true);
> }
> }
>
> The Compiler runs over it without any trouble, but the GUI is not shown. I
> saw a lot of PlugIns running with Java GUIs but I couldn't get a single one
> work! I'm very gladful for every idea.
>
> best regards
> Steve
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Running-Java-based-GUIs-as-Plug-In-tp5005165.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html


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