NervousText vs NetBeans 4.1

S

superchumbo

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
 
T

Thomas Fritsch

superchumbo said:
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
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;
}
}
 
T

Thomas Fritsch

Thomas Fritsch said:
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\"";
}
 
S

superchumbo

Thomas Fritsch said:
[...]
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)) {
selected = i;
break;
}
}
public String[] getTags() {

return values;
}

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

superchumbo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top