🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17364

Button + Checkbox + CheckboxGroup == loads of fun

#17364
From: William Yu
Date: Sun, 15 Nov 1998 00:00
55 lines
2596 bytes
Here's the setup.  I'm working on creating a few variations of the List
component -- specifically, a Checkbox List and a Button List.  The
Checkbox List component is up and running so I was thinking about how to
reuse my Checkbox List component for the Button List.  My thought was to
extend the Button class to act like a Checkbox.  The first was trivial
to implement -- the part I've having trouble with now is getting my
CheckboxButton class to work with the CheckboxGroup class.

My bright idea was the following:

    public class CheckboxButton {
        ...
        Checkbox dummy = new Checkbox();

        public CheckboxButton() {
            dummy.addItemListener(new dummyListener(this, dummy));
        }

        public void setState(boolean b) {
            if (b != dummy.getState())
                dummy.setState(b);
            ...
        }

        public void setCheckboxGroup(CheckboxGroup cbg) {
            dummy.setCheckboxGroup(cbg);
            ...
        }
    }

    public class dummyListener {
        CheckboxButton adaptee;
        Checkbox dummy;

        public dummyListener(CheckboxButton adaptee, Checkbox dummy) {
            this.adaptee = adaptee;
            this.dummy = dummy;
        }

        public void itemStateChanged(ItemEvent e) {
            adaptee.setState(dummy.getState());
        }
    }

The idea was that my CheckboxButtons would create phantom Checkboxes to
link to a CheckboxGroup.  And when the state changed due to a selection,
the state change listener would notify CheckboxButton.  Unfortunately,
it looks like itemStateChange only triggers when an AWT event causes it
to trigger.  (Meaning, setState(true) won't do it.)  So my next step was
to use dispatchEvent() to send mouse clicks & key strokes from the
Button to the Checkbox -- again, no dice.

The lack of itemStateChange when the setState() method is called leads
me to believe that CheckboxGroup is doing something else behind the
scenes.  Anybody have info info about this?
Technical Details
Message-ID: <364ED33A.4C99CE@Bigfoot.com>
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: f74b3,ad23d109ed8251a3,start
X-Google-Attributes: gidf74b3,public
From: William Yu <William_Yu@Bigfoot.com>
Subject: Button + Checkbox + CheckboxGroup == loads of fun
Date: 1998/11/15
Message-ID: <364ED33A.4C99CE@Bigfoot.com>
X-Deja-AN: 412051177
Content-Transfer-Encoding: 7bit
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language