- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to select the first item in JList
To select the first item in JList, use setSelectionInterval() method:
String values[]= { "One","Two","Three","Four","Five","Six"}; JList list = new JList(values); int begn = 0; int end = 0; list.setSelectionInterval(begn, end);
The following is an example to select the first item in JList:
Example
package my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); SwingDemo s = new SwingDemo(); JPanel panel = new JPanel(); String values[]= { "One","Two","Three","Four","Five","Six"}; list = new JList(values); int begn = 0; int end = 0; list.setSelectionInterval(begn, end); panel.add(list); frame.add(panel); frame.setSize(550,300); frame.setVisible(true); } }
Output
- Related Articles
- How to display a value when select a JList item in Java?
- Java Program to check if the second item is selected in Java JList
- Java Program to select all the items in a JList
- How to select the second index in Java JList?
- Default to and select the first item in Tkinter Listbox
- Java Program to disable the first item on a JComboBox
- How to move specific item in array list to the first item in Java?
- How to set a tooltip text for each item of a JList in Java?
- How to pre-select JComboBox item by index in Java?
- How to select one item at a time from JCheckBox in Java?
- How to select the first column in a JTable with Java?
- How to add ScrollBar to JList in Java?
- Java Program to set Selection Mode for JList only for single selection
- How to store string array in Java JList?
- How to add JList to Scroll pane in Java?

Advertisements