- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How can we clear all selections in Java Swing JList?
To clear all selections, use the List clearSelection() method in Java −
JList list = new JList(sports); list.clearSelection();
Above, the elements in Sports array is a String array −
String sports[]= { "Cricket","Football","Hockey","Rugby"};
The following is an example to clear all selection 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 sports[]= { "Cricket","Football","Hockey","Rugby"}; list = new JList(sports); list.clearSelection(); panel.add(list); frame.add(panel); frame.setSize(550,300); frame.setVisible(true); } }
Output
- Related Articles
- How to display row count in Java Swing JList
- Can we change the Cursor with Java Swing?
- How can we add different font style items to JList in Java?\n
- How can we catch a double click and enter key events for a JList in Java?\n
- How can we display all module names in Java 9?
- Java Program to select all the items in a JList
- How can we display all modules with classloaders in Java 9?
- How can I check if there are any selected items in Java JList
- How can I position JButtons vertically one after another in Java Swing?
- How can I clear or empty a StringBuilder in Java.
- How to enable multiple selections in a JFileChooser Dialog with Java?
- How to store string array in Java JList?
- How to add ScrollBar to JList in Java?
- Clear out all of the Vector elements in Java
- How to maximize JFrame in Java Swing

Advertisements