Here you can find the source of addToList(JList list, Object object)
public static void addToList(JList list, Object object)
//package com.java2s; //License from project: LGPL import javax.swing.*; public class Main { public static void addToList(JList list, Object object) { ListModel model = list.getModel(); if (model == null) { model = new DefaultListModel(); list.setModel(model);//from w w w . ja v a 2 s . c om } ; if (model instanceof DefaultListModel) { DefaultListModel listModel = (DefaultListModel) model; listModel.addElement(object); } } }