To programmatically move the list to the top : JList « Swing « Java Tutorial

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
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » Swing » JList 
14. 40. 16. To programmatically move the list to the top

The firstVisibleIndex and lastVisibleIndex properties allow you to find out which choices are currently visible. To request that a specific element be made visible, use the public void ensureIndexIsVisible(int index) method.

To programmatically move the list to the top
import java.awt.BorderLayout;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;

public class SizingSamples {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Sizing Samples");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    DefaultListModel model = new DefaultListModel();
    model.ensureCapacity(100);
    for (int i = 0; i < 100; i++) {
        model.addElement(Integer.toString(i));
    }
    JList jlist2 = new JList(model);
    
    
    JScrollPane scrollPane2 = new JScrollPane(jlist2);
    frame.add(scrollPane2, BorderLayout.CENTER);

    frame.setSize(300350);
    frame.setVisible(true);
    
    jlist2.ensureIndexIsVisible(50);
  }
}
14. 40. JList
14. 40. 1. JList
14. 40. 2. Creating JList Components
14. 40. 3. Using JListUsing JList
14. 40. 4. A container for pseud codeA container for pseud code
14. 40. 5. Storing value in Vector and adding them into JListStoring value in Vector and adding them into JList
14. 40. 6. Set selected indexSet selected index
14. 40. 7. Modifying the Data ModelModifying the Data Model
14. 40. 8. Using DefaultListModel to control the Data in a JListUsing DefaultListModel to control the Data in a JList
14. 40. 9. Sharing the Data Model for a JComboBox and JListSharing the Data Model for a JComboBox and JList
14. 40. 10. Using a Custom Data ModelUsing a Custom Data Model
14. 40. 11. Listening to JList Events with a ListSelectionListenerListening to JList Events with a ListSelectionListener
14. 40. 12. Using ListDataListener to listen to ListModel EventsUsing ListDataListener to listen to ListModel Events
14. 40. 13. Selection event for double-clicking an item in the listSelection event for double-clicking an item in the list
14. 40. 14. public Point indexToLocation(int index): returning a Point as the origin of the provided indexpublic Point indexToLocation(int index): returning a Point as the origin of the provided index
14. 40. 15. Setting the number of visible rows with setVisibleRowCount()Setting the number of visible rows with setVisibleRowCount()
14. 40. 16. To programmatically move the list to the topTo programmatically move the list to the top
14. 40. 17. ListSelectionModel ModesListSelectionModel Modes
14. 40. 18. Selection MethodsSelection Methods
14. 40. 19. To make multiple list selections, you can use the anchor and lead indices of the selection items.To make multiple list selections, you can use the anchor and lead indices of the selection items.
14. 40. 20. Adding Element-Level Tooltips to List ItemsAdding Element-Level Tooltips to List Items
14. 40. 21. Bench mark for JListBench mark for JList
14. 40. 22. Customizing a JList Look and Feel
14. 40. 23. Get index of first visible item
14. 40. 24. Get index of last visible item
14. 40. 25. Arranging Items in a JList Component
14. 40. 26. Setting a Tool Tip for an Item in a JList Component
14. 40. 27. Detecting Double and Triple Clicks on an Item in a JList Component
14. 40. 28. Methods are used to find an item
14. 40. 29. Use drag and drop to reorder a list
14. 40. 30. These methods can be used to find the range of visible items
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.