extends AbstractListModel : JList Model « Swing « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » Swing » JList Model 




extends AbstractListModel
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.AbstractListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class JBenchFrame extends JFrame {
  BorderLayout borderLayout1 = new BorderLayout();
  JList list1 = new JList();
  JButton fillButton = new JButton();

  public static void main(String[] args) {
    JBenchFrame bm = new JBenchFrame();
  }

  public JBenchFrame() {
    this.getContentPane().setLayout(borderLayout1);
    this.setSize(new Dimension(400300));
    fillButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ListData ld = new ListData();
        long tmStart = System.currentTimeMillis();
        list1.setModel(ld);
        list1.repaint();
        long tmEnd = System.currentTimeMillis();
        System.out.println(tmEnd - tmStart);

      }
    });
    fillButton.setText("Fill");
    this.getContentPane().add(new JScrollPane(list1), BorderLayout.CENTER);
    this.getContentPane().add(fillButton, BorderLayout.SOUTH);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setVisible(true);
  }

}

class ListData extends AbstractListModel {
  String[] strings = new String[10000];

  public ListData() {
    for (int i = 0; i < 10000; i++) {
      strings[i"bob" + i;
    }
  }

  public int getSize() {
    return strings.length;
  }

  public Object getElementAt(int index) {
    return strings[index];
  }
}














14.42.JList Model
14.42.1.SortedListModel: sortable JListSortedListModel: sortable JList
14.42.2.extends DefaultListModel
14.42.3.extends AbstractListModelextends AbstractListModel
14.42.4.JList: ListModel and ListSelectionModel. The ListModel handles data. ListSelectionModel works with the GUI.
14.42.5.Create a list that allows adds and removes
14.42.6.Append an item
14.42.7.Insert an item at the beginning
14.42.8.Adding and Removing an Item in a JList Component
14.42.9.Set method replaces an item
14.42.10.Methods are used to remove items
14.42.11.DefaultListModel and JList
14.42.12.Getting the Items in a JList Component
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.