Frage

There is a List containing TextFields. The problem is that these fields are not editable ! Here are codes :

    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;
    }
}

At runtime it gives something like this :

enter image description here

So how to make the TextFields editable ?

War es hilfreich?

Lösung

That is not possible in List.

List is only for displaying list of clickable items not for Text Field.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top