Login  Register

Re: TextField in Fiji

Posted by dscho on Oct 09, 2013; 10:47am
URL: http://imagej.273.s1.nabble.com/TextField-in-Fiji-tp5005091p5005098.html

Hi Andrew,

On Wed, 9 Oct 2013, AJBell wrote:

> This code:
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.frame.*;
>
> public class Plugin_Frame extends PlugInFrame {
>
> public Plugin_Frame() {
> super("Plugin_Frame");
> TextField tf = new TextField();
> add(tf);
> pack();
> GUI.center(this);
> setVisible(true);
> }
>
> }
>
> produces the following error
>
>    File....\Plugin_Frame.java:12: cannot find symbol
>    symbol  : method add(TextField)
>    location: class Plugin_Frame
> add(tf);
>
> But only in Fiji - it works fine with ImageJ.

You encountered the perils of unprecise importing. If you start
Plugin>Utilities>Find Jar For Class and type in "TextField" you will find
that it is in Volume_Viewer.jar. If you type in "java.awt.TextField", you
will find the correct .jar instead. Since you did not import that
TextField explicitly, Java will pick the TextField class that is in the
default package.

So if you insert

        import java.awt.TextField;

*before* all of these wildcard imports, it will actually work.

Ciao,
Johannes

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