Re: setEnabled(false) in new GenericDialog

Posted by ctrueden on
URL: http://imagej.273.s1.nabble.com/setEnabled-false-in-new-GenericDialog-tp3688595p3688600.html

Hi Michael & Michael,

We ran into these same issues when coding the Bio-Formats Importer plugin.
You can see our approach at:

https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/src/loci/plugins/importer/ImporterDialog.java?rev=6039#L403

The method (verifyOptions) is essentially a big bag of logic for controlling
which options get grayed out in which situations. To address the Mac OS X
glitch, we have a horrible hack at:

https://skyking.microscopy.wisc.edu/trac/java/browser/trunk/components/loci-plugins/src/loci/plugins/importer/ImporterDialog.java?rev=6039#L616

The hack cycles the keyboard focus across all the components and sleeps a
bit (100ms), which seems to force the UI to update on most (all?) Mac OS X
systems.

For what it's worth, we are exploring ways to simplify some of this
complexity for ImageJ2.

HTH,
Curtis

On Wed, Apr 14, 2010 at 10:19 AM, Michael Doube <[hidden email]>wrote:

> Hi Michael,
>
> Thank you for your response.
>
>
>  Input into the text field should be disabled, however.
>>
>
> Unfortunately, it is not disabled until after any one of the dialog fields
> is actively changed by the user (including the TextField in question).  So
> if my code is good, then this seems to me to be a bug - unable to set
> initial state of dialog fields to setEnabled(false).
>
>  (2) SetEnabled in DialogItemChanged of a DialogListener will often
>> fail on a Macintosh ...
>>
>
>  On the Mac, the easiest work around would be a delay of 100 millisec
>> before a setEnabled call in a DialogListener.
>>
>
> So if an event triggers a DialogListener to make several changes to a
> dialog, we should wait 100 ms between applying each change?
>
>
> 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
>>>
>>