有一个包含 TextFields 的列表。问题是这些字段不可编辑!以下是代码:
public formConstructor()
{
...
private Vector vList = new Vector(); // datasource of the list
private CListCellProduits listRenderer;
private List list;
...
listRenderer = new CListCellProduits(20);
vList.addElement(new String("P001;"));
vList.addElement(new String("P002;"));
list = (new ListUtil(vList)).createList(listRenderer);
addComponent(list);
...
}
public class CListCellProduits extends Container implements ListCellRenderer {
private Label focus = new Label("");
private Label lData;
private Champ sortie = new Champ("123", TextArea.NUMERIC);
private Champ dispo = new Champ("123", TextArea.NUMERIC);
private int widthCommun;
private Container cRow1 = new Container(new BoxLayout(BoxLayout.X_AXIS));
public CListCellProduits(int widthCommun)
{
super();
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
lData = new Label("");
sortie.setPreferredW(widthCommun);
dispo.setPreferredW(widthCommun);
this.widthCommun = widthCommun;
cRow1.addComponent(lData);
cRow1.addComponent(sortie);
cRow1.addComponent(dispo);
addComponent(cRow1);
}
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
{
Content entry = null;
if (value instanceof Content)
entry = (Content)value;
if (!"".equals(entry.getColumn(0)))
lData.setText(entry.getColumn(0));
else
lData.setText("-");
lData.setPreferredW(widthCommun);
list.repaint();
return this;
}
public Component getListFocusComponent(List arg0)
{
return focus;
}
}
public class ListUtil {
private Vector data = new Vector();
private Content[] contents;
public ListUtil(Vector vData)
{
data = vData;
contents = new Content[vData.size()];
}
public List createList(CListCellProduits renderer)
{
CList theList;
for(int i = 0; i < data.size(); i++)
{
contents[i] = new Content(String.valueOf(data.elementAt(i)));
}
theList = new CList(contents, renderer);
return theList;
}
}
public class CList extends List {
public CList(Object[] data, CListCellProduits renderer)
{
super(data);
setListCellRenderer(renderer);
setScrollAnimationSpeed(getScrollAnimationSpeed()/4);
}
}
public class Champ extends TextField {
public Champ(String imo)
{
super();
setReplaceMenu(false);
setInputModeOrder(new String[]{imo});
}
public Champ(String imo, int contrainte)
{
super();
setReplaceMenu(false);
setInputModeOrder(new String[]{imo});
setConstraint(contrainte);
}
protected Command installCommands(Command clear, Command t9)
{
return null;
}
}
在运行时它给出了这样的东西:
那么如何使 TextFields 可编辑呢?