🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12177

using setEnabled(b) on a JPanel

#12177
From: Timothy E. Raborn
Date: Tue, 09 Feb 1999 00:00
118 lines
4780 bytes
--------------811A27FE66615278B9F39060
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I've tried using setEnabled(false) on a JPanel hoping all of the
components within that panel would be disabled, but I guess this method
doesn't propagate down the component tree.

I then tried sub classing JPanel and overriding the setEnabled method as
follows:

  public void setEnabled(boolean b)
  {
    setEnabledComponentTree(this, b);
    repaint();  // not really sure if this is necessary
  }

  private void setEnabledComponentTree (Component c, boolean b)
  {
    Container c1 = (Container) c;

    if (c1.getComponentCount() > 0)
    {
      for (int i = 0;  i < c1.getComponentCount();  i++)
      {
        setEnabledComponentTree(c1.getComponent(i), b);
      }

    }
    else
    {
      //c.setEnabled(b);  <- giving me problems with stack overflows
(recursive loops)
      super.setEnabled(b);
    }

  }



This is not having an effect on my sub components either, though it
appears as though the logic flow of the program is OK (judging by my
debug output, which I didn't show in the above code).

Does anyone see a problem with my code or is there another way of doing
this?  My guess is that the problem may lie in the "super.setEnabled(b)"
call.

I should add that I "sort of" had this working at some point, and I
think it may have stopped working completely when I upgraded to Swing
1.1.  The code was developed using JBuilder and its built-in jdk
(1.1.6).   I say "sort of" because it didn't really work for all
components.  You could still interact with JComboBoxes for one.

Any help is much appreciated!

Thanks

-Tim


--------------811A27FE66615278B9F39060
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I've tried using setEnabled(false) on a JPanel hoping all of the components
within that panel would be disabled, but I guess this method doesn't propagate
down the component tree.
<p>I then tried sub classing JPanel and overriding the setEnabled method
as follows:
<p><tt>&nbsp; public void setEnabled(boolean b)</tt>
<br><tt>&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp; setEnabledComponentTree(this, b);</tt>
<br><tt>&nbsp;&nbsp;&nbsp; repaint();&nbsp; // not really sure if this
is necessary</tt>
<br><tt>&nbsp; }</tt>
<p><tt>&nbsp; private void setEnabledComponentTree (Component c, boolean
b)</tt>
<br><tt>&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp; Container c1 = (Container) c;</tt>
<p><tt>&nbsp;&nbsp;&nbsp; if (c1.getComponentCount() > 0)</tt>
<br><tt>&nbsp;&nbsp;&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0;&nbsp; i &lt; c1.getComponentCount();&nbsp;
i++)</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setEnabledComponentTree(c1.getComponent(i),
b);</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</tt>
<p><tt>&nbsp;&nbsp;&nbsp; }</tt>
<br><tt>&nbsp;&nbsp;&nbsp; else</tt>
<br><tt>&nbsp;&nbsp;&nbsp; {</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //c.setEnabled(b);&nbsp; &lt;- giving
me problems with stack overflows (recursive loops)</tt>
<br><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; super.setEnabled(b);</tt>
<br><tt>&nbsp;&nbsp;&nbsp; }</tt>
<p><tt>&nbsp; }</tt>
<br>&nbsp;
<br>&nbsp;
<p>This is not having an effect on my sub components either, though it
appears as though the logic flow of the program is OK (judging by my debug
output, which I didn't show in the above code).
<p>Does anyone see a problem with my code or is there another way of doing
this?&nbsp; My guess is that the problem may lie in the "super.setEnabled(b)"
call.
<p>I should add that I "sort of" had this working at some point, and I
think it may have stopped working completely when I upgraded to Swing 1.1.&nbsp;
The code was developed using JBuilder and its built-in jdk (1.1.6).&nbsp;&nbsp;
I say "sort of" because it didn't really work for all components.&nbsp;
You could still interact with JComboBoxes for one.
<p>Any help is much appreciated!
<p>Thanks
<p>-Tim
<br>&nbsp;</html>

--------------811A27FE66615278B9F39060--
Technical Details
Message-ID: <36C0999F.210C1476@ametro.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,d047d73010301ae2,start
X-Google-Attributes: gid111d45,public
From: "Timothy E. Raborn" <traborn@ametro.net>
Subject: using setEnabled(b) on a JPanel
Date: 1999/02/09
Message-ID: <36C0999F.210C1476@ametro.net>
X-Deja-AN: 442522625
X-Accept-Language: en
Content-Type: multipart/alternative; boundary="------------811A27FE66615278B9F39060"
Organization: American Metrocomm Internet Services
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing