Posted by
Michael Schmid on
Apr 15, 2010; 7:51am
URL: http://imagej.273.s1.nabble.com/setEnabled-false-in-new-GenericDialog-tp3688595p3688596.html
Hi Michael,
the following code produces a disabled input field on Mac OS X. If
the input field is enabled on your system, it is a bug in your java
version or Ubuntu.
import java.awt.*;
import java.util.Vector;
import ij.*;
import ij.gui.*;
import ij.plugin.PlugIn;
public class TestEnabled implements PlugIn {
public void run(String arg) {
GenericDialog gd = new GenericDialog("test");
gd.addNumericField("How many times?", 1, 0);
Vector numbers = gd.getNumericFields();
TextField num = (TextField) numbers.get(0);
num.setEnabled(false);
gd.showDialog();
}
}
Michael
________________________________________________________________
On 14 Apr 2010, at 02:43, Doube, Michael wrote:
> Hi All,
>
> I have a TextField and a Checkbox in a GenericDialog. I want the
> TextField to be setEnabled(false) , i.e. greyed out, when the
> Checkbox is false. This I can accomplish using a DialogListener
> when the user clicks on the Checkbox. But I want the default
> setting to be that the Checkbox is false and the TextField is
> correspondingly greyed out - i.e. before user input changes the
> state of any of the Components, triggering the Listener.
>
> I've tried getting the Vector of numeric fields, then getting the
> correct element using both get() and elementAt(), and setEnabled
> (false), directly before shwoDialog() but it doesn't seem to work.
>
> ...
> gd.addCheckbox("Do it", false)
> gd.addNumericField("How many times?", 1, 0); //to be greyed out
> initially
> ...
> Vector<?> numbers = gd.getNumericFields();
> TextField num = (TextField) numbers.get(3) // or .elementAt(3);
> num.setEnabled(false);
> showDialog();
>
> Any ideas? I'm on Ubuntu 10.04, JRE 1.6 19, IJ 1.43s
>
> Michael