Posted by
Rasband, Wayne (NIH/NIMH) [E] on
May 09, 2014; 3:12am
URL: http://imagej.273.s1.nabble.com/MultiLineLabel-in-GenericDialog-tp5007637p5007646.html
On May 8, 2014, at 1:38 PM, Stephan Preibisch wrote:
> Hi everyone,
>
> I want to use a MultiLineLabel to display text in a GenericDialog. Using a listener I want to change that comment (the MultiLineLabel) depending on a choice in one of the other elements. However, there is no method to set the text of the MultiLineLabel.
The latest ImageJ daily build (1.49a19) adds a setText() method to the MultiLineLabel class. The following example plugin, which is recordable, demonstrates how to use this method.
-wayne
import ij.*;
import ij.plugin.PlugIn;
import ij.gui.*;
import java.awt.*;
public class Dialog_Test implements PlugIn, DialogListener {
private String divider = "----------";
private String defaultText = "abcdef";
private static GenericDialog gd;
String text;
public void run(String arg) {
showDialog();
IJ.log("Text: "+text);
}
void showDialog() {
gd = new GenericDialog("Test Dialog");
gd.addStringField("Text: ", defaultText);
gd.addMessage(divider+"\n"+defaultText+"\n"+divider);
gd.addDialogListener(this);
gd.showDialog();
}
public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
text = gd.getNextString();
MultiLineLabel label = (MultiLineLabel)gd.getMessage();
label.setText(divider+"\n"+text+"\n"+divider);
return true;
}
}
> Until now, I used a Label, where after adding the message " " to the GenericDialog, I changed the text which then contains "\n"'s before calling showDialog(). This way I got a Label which has multiple lines and a setText() method that I can call from the Listener. I just recently figured out that this works only under Mac, not Windows and Linux. Bummer.
>
> Is there any way to set the text of a MultiLineLabel without using reflections?
> Alternatively, I could use multiple normal Labels, but then the distance between them is far too large, it does not look like a block.
>
> If this all doesn't work, I will extend the MultiLineLabel class and add it as my own element. But if there is a more elegant way would be nice.
>
> Thanks a lot,
> Stephan
> ---
>
> Dr. Stephan Preibisch
> HFSP Fellow
> Robert H. Singer / Eugene Myers lab
>
> Albert Einstein College of Medicine / HHMI Janelia Farm / MPI-CBG
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html