NervousText vs NetBeans 4.1  
Author Message
superchumbo





PostPosted: 2005-10-17 7:05:00 Top

java-programmer, NervousText vs NetBeans 4.1 Hello,

I'm trying to learn how to create custom property editors for own javabeans.
I'm using sun's tutorial from webpage
http://java.sun.com/developer/onlineTraining/Beans/Beans4/nervous07.html
Everything is going well, i'm able to add this bean as new component
toNetBeans
by Palette Manager, i'm able to add this new component to jFrame,
but when I'm trying to change "text" property in properties editor,
NetBeans adds in initComponents() line:
nervousText071.setText(???);
Does anybody know what is the reason of malfunction? Is it my fault?

this is the property editor class:

package sun.beanbox.beans;
import java.beans.*;

public class NervousText07TextPropertyEditor
extends PropertyEditorSupport {
public String[] getTags() {
String values[] = {
"Nervous Text",
"Anxious Text",
"Funny Text",
"Wobbly Text"};
return values;
}
}

The rest of sources is on that webpage.

Many thanks in advance,
superchumbo


 
Thomas Fritsch





PostPosted: 2005-10-17 8:21:00 Top

java-programmer >> NervousText vs NetBeans 4.1 "superchumbo" <email***@***.com> wrote:
> I'm trying to learn how to create custom property editors for own
> javabeans.
> I'm using sun's tutorial from webpage
> http://java.sun.com/developer/onlineTraining/Beans/Beans4/nervous07.html
> Everything is going well, i'm able to add this bean as new component
> toNetBeans
> by Palette Manager, i'm able to add this new component to jFrame,
> but when I'm trying to change "text" property in properties editor,
> NetBeans adds in initComponents() line:
> nervousText071.setText(???);
> Does anybody know what is the reason of malfunction? Is it my fault?

The PropertyEditorSupport class has the method
public String getJavaInitializationString() {
return "???";
}
I think you have to override this method in your class, so that it returns a
meaningful and syntactical correct piece of Java code.

See
<http://java.sun.com/j2se/1.4.2/docs/api/java/beans/PropertyEditorSupport.html#getJavaInitializationString()>
>
> this is the property editor class:
>
> package sun.beanbox.beans;
> import java.beans.*;
>
> public class NervousText07TextPropertyEditor
> extends PropertyEditorSupport {
> public String[] getTags() {
> String values[] = {
> "Nervous Text",
> "Anxious Text",
> "Funny Text",
> "Wobbly Text"};
> return values;
> }
> }
>
--
"TFritsch$t-online:de".replace(':','.').replace('$','@')


 
Thomas Fritsch





PostPosted: 2005-10-17 9:33:00 Top

java-programmer >> NervousText vs NetBeans 4.1 "Thomas Fritsch" <email***@***.com> wrote:
[...]
> The PropertyEditorSupport class has the method
> public String getJavaInitializationString() {
> return "???";
> }
> I think you have to override this method in your class, so that it returns
> a meaningful and syntactical correct piece of Java code.
For example:
public String getJavaInitializationString() {
return "\"Nervous Text\"";
}
--
"TFritsch$t-online:de".replace(':','.').replace('$','@')


 
 
superchumbo





PostPosted: 2005-10-17 10:16:00 Top

java-programmer >> NervousText vs NetBeans 4.1 > "Thomas Fritsch" <email***@***.com> wrote:
> [...]
> > The PropertyEditorSupport class has the method
> > public String getJavaInitializationString() {
> > return "???";
> > }
> > I think you have to override this method in your class, so that it
returns
> > a meaningful and syntactical correct piece of Java code.
> For example:
> public String getJavaInitializationString() {
> return "\"Nervous Text\"";
> }

many thanks!

so, in this case, NervousText07TextPropertyEditor class could look as
follows:

package sun.beanbox.beans;

import java.beans.*;

public class NervousText07TextPropertyEditor extends PropertyEditorSupport {

private int selected=0;
private String values[] = {
"Nervous Text",
"Anxious Text",
"Funny Text",
"Wobbly Text"
};

public String getAsText() {
return values[selected];
}

public void setAsText(String text)
throws IllegalArgumentException {
Object oldValue = getValue();
for(selected = 0;
selected < values.length &&
!values[selected].equals(text);
selected++);
if (selected == values.length)
selected = 0;
Object newValue = getValue();
firePropertyChange();
}

public Object getValue() {
return values[selected];
}

public void setValue(Object value) {
selected = 0;
if (value != null)
for(int i=0; i < values.length; i++)
if (value.equals(values[i])) {
selected = i;
break;
}
}
public String[] getTags() {

return values;
}

public String getJavaInitializationString() {
return "\""+values[selected]+"\"";
}
}

superchumbo