예시2
public class MyListBox extends ListBox implements
LeafValueEditor<String> {
@Override
public void setValue(String value) {
if (value == null) {
setSelectedIndex(-1);
return;
}
for (int i=0;i<getItemCount();i++) {
if (getValue(i).equals(value)) {
setSelectedIndex(i);
return;
}
}
for (int i=0;i<getItemCount();i++) {
if (getItemText(i).equals(value)) {
setSelectedIndex(i);
return;
}
}
}
@Override
public String getValue() {
if (getSelectedIndex() == -1)
return null;
if (getItemText(getSelectedIndex()).trim().equals(""))
return null;
String value = getValue(getSelectedIndex());
if (value != null) {
return value;
}
return getItemText(getSelectedIndex());
}
}
댓글 없음:
댓글 쓰기