Article View: borland.public.jbuilder.java.language
Article #15600Re: Make that bean with bound property
From: Tor Iver Wilhelmsen
Date: Thu, 27 May 1999 00:00
Date: Thu, 27 May 1999 00:00
30 lines
1583 bytes
1583 bytes
"John Hines" <jrhines@onramp.net> writes:
> I'm having trouble creating a bean with bound property. Is there an example
> in JB2 or JB3? Or, does somebody have one they can post?
Go via the BeansExpress (the "Bean" tab under the editor, and mark it
as bound when you create it usinbg the property wizard. Basically,
what you need are addPropertyChangeListener(),
removePropertyChangeListener(), firePropertyChange() and have the
setter methods fire this later on. Common in Swing is to encode the
bound property names as constants:
public static final String FOO_PROPERTY = "foo";
public void setFoo(int newFoo) {
int oldFoo = foo;
foo = newFoo;
firePropertyChange(new PropertyChangeEvent(this, FOO_PROPERTY,
new Integer(oldFoo), new Integer(newFoo)));
}
That way, you can compare ref equality in the listener instead of
using equals:
if (evt.getPropertyName() == MyClassWithProperty.FOO_PROPERTY)
//...
For basic assistance for the add/remove/fire methods use a delegate by
making a PropertyChangeSupport object. Or do it the Vector way that
JBuilder does.
Technical Details
Message-ID:
<un1yrq7yj.fsf@sds.no>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7ihecr$2f58@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,3edcbd40583beda1 X-Google-Attributes: gidf74b3,public From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no> Subject: Re: Make that bean with bound property Date: 1999/05/27 Message-ID: <un1yrq7yj.fsf@sds.no> X-Deja-AN: 482631901 Sender: towi@SDSA1761 References: <7ihecr$2f58@forums.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.language