Article View: borland.public.jbuilder.java.language
Article #7689addImpl() - what went wrong?
From: Maxim Golubitsky
Date: Sun, 27 May 2001 13:39
Date: Sun, 27 May 2001 13:39
62 lines
2556 bytes
2556 bytes
Hi,
I wrote some class (see below), that extends Panel and have on it Checkbox
and Panel.
All Components should be added to inner Panel and when Checkbox is checked
they should be enabled and vice versa.
The problem is, that Checkbox and any components added to Panel doesn't
respond to mouse.
I think, this caused because I overrode addImpl(), but have no idea why this
happens and how to solve this problem.
Please help.
--
Regards,
Maxim Golubitsky
import java.awt.*;
import java.awt.event.*;
public class MyPanel extends Panel {
Checkbox checkbox = new Checkbox();
Panel panel = new Panel();
FlowLayout flowLayout1 = new FlowLayout();
public MyPanel(String caption) {
checkbox.setLabel(caption);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public MyPanel(){
this("");
}
private void jbInit() throws Exception {
this.setLayout(flowLayout1);
flowLayout1.setAlignment(FlowLayout.LEFT);
checkbox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(ItemEvent e) {
checkbox_itemStateChanged(e);
}
});
this.add(checkbox, null);
this.add(panel, null);
}
protected void addImpl(Component component, Object obj, int i){
if(component == panel || component == checkbox)
super.addImpl(component, obj, i);
else
panel.add(component, obj, i);
}
void checkbox_itemStateChanged(ItemEvent e) {
boolean b = checkbox.getState();
for (int i = 0; i < panel.getComponentCount(); i++) {
panel.getComponent(i).setEnabled(b);
}
}
}
Technical Details
Message-ID:
<3b10f569_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!newsfeed2.skycache.com!newsfeed.skycache.com!Cidera!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,64bd44c5695f9915,start X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-05-27 05:45:23 PST From: "Maxim Golubitsky" <maxim@tradertools.com> Newsgroups: borland.public.jbuilder.java.language Subject: addImpl() - what went wrong? Date: Sun, 27 May 2001 15:39:18 +0200 Lines: 64 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 212.29.213.11 Message-ID: <3b10f569_2@dnews> X-Trace: dnews 990967145 212.29.213.11 (27 May 2001 05:39:05 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!newsfeed2.skycache.com!newsfeed.skycache.com!Cidera!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews