add To JList List - Java Swing

Java examples for Swing:JList

Description

add To JList List

Demo Code


//package com.java2s;

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 ww .j  av a 2s .c o  m*/
        }
        ;
        if (model instanceof DefaultListModel) {
            DefaultListModel listModel = (DefaultListModel) model;
            listModel.addElement(object);
        }
    }
}

Related Tutorials