Login  Register

Re: Running Java based GUIs as Plug In

Posted by Michael Schmid on Oct 15, 2013; 6:16pm
URL: http://imagej.273.s1.nabble.com/Running-Java-based-GUIs-as-Plug-In-tp5005165p5005189.html

Hi Steve,

the plugin 'My_Plugin' copied from the mail below compiles and runs with no error in my version of ImageJ:
I tried ImageJ 1.46r and the daily build ImageJ 1.48e12
Java 1.6.0_51 [64-bit] Mac OSX 10.6.8

Michael
________________________________________________________________
On Oct 15, 2013, at 19:42, Influenza wrote:

> Thanks for your fast reaction!
>
> But unfortunatelly it still doesn't work.
>
> "java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at ij.plugin.CompilerTool$JavaxCompilerTool.compile(Compiler.java:366)
> at ij.plugin.Compiler.compile(Compiler.java:150)
> at ij.plugin.Compiler.compileAndRun(Compiler.java:71)
> at ij.plugin.Compiler.run(Compiler.java:37)
> at ij.IJ.runPlugIn(IJ.java:166)
> at ij.IJ.runPlugIn(IJ.java:149)
> at ij.plugin.frame.Editor.compileAndRun(Editor.java:347)
> at ij.plugin.frame.Editor.actionPerformed(Editor.java:601)
> at java.awt.MenuItem.processActionEvent(MenuItem.java:627)
> at java.awt.MenuItem.processEvent(MenuItem.java:586)
> at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:317)
> at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:305)
> at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:320)
> at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:305)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:602)
> at
> java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
> at
> java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
> at
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
> Caused by: java.lang.IllegalArgumentException: All compilation units must
> be of SOURCE kind
> at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:203)
> ... 25 more"
>
> have you tried it yourselve or any ideas left?
>
> Beste regards
> steve
>
>
>
> 2013/10/15 John Hayes [via ImageJ] <[hidden email]>
>
>> 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
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://imagej.1557.x6.nabble.com/Running-Java-based-GUIs-as-Plug-In-tp5005165p5005179.html
>> To unsubscribe from Running Java based GUIs as Plug In, click here<
>> .
>> NAML<
http://imagej.1557.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Running-Java-based-GUIs-as-Plug-In-tp5005165p5005185.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