Posted by
Albert Cardona on
Feb 22, 2008; 2:39pm
URL: http://imagej.273.s1.nabble.com/Pause-in-a-java-plugin-program-tp3697005p3697012.html
Hi Joachim,
>> Is this possible, any example code that already does something similar?
Yes it is posible. All you need is to add a listener to the dialog.
See an example of using checkboxes to control the enabled/disabled input
status of any other components of GenericDialog:
http://repo.or.cz/w/trakem2.git?a=blob;f=ini/trakem2/utils/Utils.java;h=cb7545f6e14ebe83a7be72a230ba49b4a6ae98a8;hb=0edb0e6a735a8db64f0e1b80b566728e863b10e0
All you need to pass it is any component that comes from a
GenericDialog, for example any of the items in the Vector returned by
methods such as getNumericFields() etc.
724 /** A helper for GenericDialog checkboxes to control the enabled
state of other GUI elements in the same dialog. */
725 static public final void addEnablerListener(final Checkbox
master, final Component[] enable, final Component[] disable) {
726 master.addItemListener(new ItemListener() {
727 public void itemStateChanged(ItemEvent ie) {
728 if (ie.getStateChange() == ItemEvent.SELECTED) {
729 process(enable, true);
730 process(disable, false);
731 } else {
732 process(enable, false);
733 process(disable, true);
734 }
735 }
736 private void process(final Component[] c, final boolean
state) {
737 if (null == c) return;
738 for (int i=0; i<c.length; i++)
c[i].setEnabled(state);
739 }
740 });
741 }
--
Albert Cardona
http://www.mcdb.ucla.edu/Research/Hartenstein/acardona