From fe33ed950e14900afd6516d66c8cf4375d7a78ba Mon Sep 17 00:00:00 2001 From: mdb Date: Tue, 26 Mar 2002 19:32:16 +0000 Subject: [PATCH] Added setEnabled() which sets the enabled state of a container and all of its children. git-svn-id: https://samskivert.googlecode.com/svn/trunk@681 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/swing/util/SwingUtil.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java b/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java index 51156b39..f3d160fc 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java +++ b/projects/samskivert/src/java/com/samskivert/swing/util/SwingUtil.java @@ -1,5 +1,5 @@ // -// $Id: SwingUtil.java,v 1.5 2001/09/14 20:00:08 shaper Exp $ +// $Id: SwingUtil.java,v 1.6 2002/03/26 19:32:16 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -81,4 +81,28 @@ public class SwingUtil poly.addPoint(x, y); return poly; } + + /** + * Enables (or disables) the specified component, and all of its + * children. A simple call to {@link Container#setEnabled} + * does not propagate the enabled state to the children of a + * component, which is senseless in our opinion, but was surely done + * for some arguably good reason. + */ + public static void setEnabled (Container comp, boolean enabled) + { + // set the state of our children + int ccount = comp.getComponentCount(); + for (int i = 0; i < ccount; i++) { + Component child = comp.getComponent(i); + if (child instanceof Container) { + setEnabled((Container)child, enabled); + } else { + child.setEnabled(enabled); + } + } + + // set our state + comp.setEnabled(enabled); + } }