If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Adding items to a JList at run time.

This will probably seem like a very "noob" question but I think this is the appropriate forum for this?

Anyway, I am VERY new to java and come from a .Net background. I am making an new JPanel and added some controls to the panel (text fields, check boxes, etc.) No problems there. Now, I've added a couple of Jlist controls at design time and they function properly.

Now I want to be able to add string objects to a JList control at run time and can't figure out how. Here is my code that works when creating the control at "design time".

you should use a class which extends AbstractListModel and implement its methods.

public int getSize()
public Object getElementAt(int n)

first one will return an int value, it will be the number of items in your List model.
second one will send the n. item of the model.
List will call them and update it's view.
its a very flexible design.
(you can put a List or array in your class with add ,remove methods.)