FileDocCategorySizeDatePackage
FilteredJList.javaAPI DocExample3255Mon Jan 09 11:01:58 GMT 2006None

FilteredJList

public class FilteredJList extends JList

Fields Summary
private FilterField
filterField
private int
DEFAULT_FIELD_WIDTH
Constructors Summary
public FilteredJList()


      
        super();
        setModel (new FilterModel());
        filterField = new FilterField (DEFAULT_FIELD_WIDTH);
    
Methods Summary
public voidaddItem(java.lang.Object o)

        ((FilterModel)getModel()).addElement (o);
    
public javax.swing.JTextFieldgetFilterField()

        return filterField;
    
public static voidmain(java.lang.String[] args)

        String[] listItems = {
            "Chris", "Joshua", "Daniel", "Michael",
            "Don", "Kimi", "Kelly", "Keagan"
        };
        JFrame frame = new JFrame ("FilteredJList");
        frame.getContentPane().setLayout (new BorderLayout());
        // populate list
        FilteredJList list = new FilteredJList();
        for (int i=0; i<listItems.length; i++)
            list.addItem (listItems[i]);
        // add to gui
        JScrollPane pane =
            new JScrollPane (list,
                             ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                             ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        frame.getContentPane().add (pane, BorderLayout.CENTER);
        frame.getContentPane().add (list.getFilterField(),
                                    BorderLayout.NORTH);
        frame.pack();
        frame.setVisible(true);
    
public voidsetModel(javax.swing.ListModel m)

        if (! (m instanceof FilterModel))
            throw new IllegalArgumentException();
        super.setModel (m);