我正在尝试使用javafx bean设置并获取某些字段的值。问题是我能够使用“StringProperty specialization”但不能使用“StringProperty degrees []”这是一个字符串属性数组,因为下面代码中的set方法不起作用:
private StringProperty degrees[];
//getter and setter for degrees array
public final void setDegrees(String[] degrees) {
**this.degreesProperty().set(degrees);**
}
public final StringProperty[] degreesProperty() {
if (degrees == null) {
SimpleStringProperty degree[]=new SimpleStringProperty[100];
degree[0]=new SimpleStringProperty("");
degree[1]=new SimpleStringProperty("");
degrees =degree;
return degrees;
} else {
return degrees;
}
}
下面的代码工作正常:
private StringProperty specialization;
//getter and setter for specialization
public final void setSpecialization(String specialization) {
this.specializationProperty().set(specialization);
}
public final StringProperty specializationProperty() {
if (specialization == null) {
specialization = new SimpleStringProperty("");
return specialization;
} else {
return specialization;
}
}
public final String getSpecialization() {
if (specialization != null) {
return specialization.get();
} else {
return "";
}
}