Skip to content, Skip to search


Tips for developers

215 bytes added, 30 January
no edit summary
= Compile & Execute a Class =
You do not need to call ''<code>javac'' </code> yourself with a long ''classpath'':
<source lang="bash">
Sometimes, the compiler complains about a class not having a certain method or interface, but you ''know'' it must contain it. More often than not, that class exists in different versions in your classpath. Find out with
<source lang="bash">$ ./fiji bin/ the.class.youre.looking.For</source>
If you want to do that with an installed Fiji (i.e. when bin/ is missing), you can start the [[Script Editor]] and execute a BeanShell like this:
<source lang="java">
import ij.IJ;
This will output the URL to the ''.class'' file, including the path to the enclosing ''.jar'' file.
== How to show a plot ==
ImageJ offers the ''<code>ij.gui.Plot'' </code> class to make a window showing a plot. Use it like this:
<source lang="java">
To add another plot to the same window, use the ''<code>addPoints()'' </code> method:
<source lang="java">
You might need to adjust the bounding box if the second plot does not match the bounding box of the first one by using the ''<code>setLimits()'' </code> method before the call to ''<code>plot.draw();''</code>
== Duplicate, or convert between, ''ImageProcessor'' types ==
The ''<code>ImageProcessor'' </code> class has several useful methods: [ duplicate()], [ convertToByte()], [ convertToFloat()],
[ convertToRGB()], and [ convertToShort()].
'''Note:''' do <u>not</u> use the ''<code>getString()'' </code> or ''<code>getInt()''</code>; These methods do not have any setter methods, and they do <u>not</u> access the same values as the ''<code>get()'' </code> method (''<code>get()'' </code> actually prefixes the keys with a dot)!
== How to turn a number into a string, using a given number of decimal places ==
Use the ''<code>d2s()'' </code> method of the ''<code>ij.IJ'' </code> class:
<source lang="java">
:''Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread.''
When has a Swing component been realized? When it is visible inside Window or ''JFrame '' that got a call to ''<code>setVisible(true)''</code>. This implies that its ''<code>paint(Graphics)'' </code> method has been called or will be called soon.
These are the methods that can realize a component, or rather, methods called on a ''Window '' or ''Frame '' or ''JFrame '' that will realize all its children components:
<source lang="java">
There is a class which helps you with all this: [ SwingUtilities]. Example: to call ''<code>pack()'' </code> from within the constructor (which might or might not be called from the Event Dispatch Thread):
<source lang="java">