Article View: borland.public.jbuilder.java.swing
Article #12177using setEnabled(b) on a JPanel
From: Timothy E. Raborn
Date: Tue, 09 Feb 1999 00:00
Date: Tue, 09 Feb 1999 00:00
118 lines
4780 bytes
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> public void setEnabled(boolean b)</tt>
<br><tt> {</tt>
<br><tt> setEnabledComponentTree(this, b);</tt>
<br><tt> repaint(); // not really sure if this
is necessary</tt>
<br><tt> }</tt>
<p><tt> private void setEnabledComponentTree (Component c, boolean
b)</tt>
<br><tt> {</tt>
<br><tt> Container c1 = (Container) c;</tt>
<p><tt> if (c1.getComponentCount() > 0)</tt>
<br><tt> {</tt>
<br><tt> for (int i = 0; i < c1.getComponentCount();
i++)</tt>
<br><tt> {</tt>
<br><tt> setEnabledComponentTree(c1.getComponent(i),
b);</tt>
<br><tt> }</tt>
<p><tt> }</tt>
<br><tt> else</tt>
<br><tt> {</tt>
<br><tt> //c.setEnabled(b); <- giving
me problems with stack overflows (recursive loops)</tt>
<br><tt> super.setEnabled(b);</tt>
<br><tt> }</tt>
<p><tt> }</tt>
<br>
<br>
<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? 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.
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.
<p>Any help is much appreciated!
<p>Thanks
<p>-Tim
<br> </html>
--------------811A27FE66615278B9F39060--
Technical Details
Message-ID:
<36C0999F.210C1476@ametro.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow 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