{"id":38669,"date":"2016-06-28T15:00:03","date_gmt":"2016-06-28T12:00:03","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=38669"},"modified":"2016-06-28T00:09:18","modified_gmt":"2016-06-27T21:09:18","slug":"java-swing-list-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/","title":{"rendered":"JAVA Swing List Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p><code>JList<\/code> is a swing component through which we can display the list of objects. This swing component allows user to select one or more elements. Lists can have many items, so they are often put in scroll panes. A separate model, <code>ListModel<\/code>, maintains the contents of the list. An array of objects can be easily displayed using the <code>JList<\/code> constructor that builds a read only <code>ListModel<\/code> instance automatically.<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<h2>2. JAVA Swing List<\/h2>\n<h3>2.1. Setup<\/h3>\n<p>This Example demonstrates how to create a List using Swing in eclipse.<\/p>\n<p><b>Prerequisite<\/b><br \/>\nThis example is developed on Eclipse therefore a compatible Eclipse IDE is required to be installed on the system.<br \/>\nWe also need WindowBuilder tool to be installed on Eclipse IDE for the easiness of the work. To learn how to install WindowBuilder tool please visit the <b> Setup section 2.1<\/b> of the following link <b>Setup section 2.1<\/b> of the following link <a href=\"https:\/\/examples.javacodegeeks.com\/desktop-java\/swing\/java-swing-form-example\/\"><strong>click here<\/strong><\/a><\/p>\n<p>Create a new JAVA project lets say swing_1<\/p>\n<ul>\n<li>Go to src\u2192 right click\u2192 New\u2192 Other\u2192 WindowBuilder\u2192 select Swing Designer\u2192 Application Window.<\/li>\n<li>Enter the name of the application(eg. SwingListExample ) and click finish.<\/li>\n<\/ul>\n<p>This will create SwingListExample.java file and will provide Source and Design tab.<\/p>\n<h3>2.2 Creating a List<\/h3>\n<p>In this example we will dynamically add and remove element to and from a list using Hire and Fire Button. To create a list a model ,i.e, <code>ListModel<\/code> is required.<\/p>\n<p>A <code>ListModel<\/code> can be supplied directly to a <code>JList<\/code> by way of a constructor or the setModel method. A correct <code>ListModel<\/code> implementation notifies the set of <code>javax.swing.event.ListDataListeners<\/code> that have been added to it, each time a change occurs.<\/p>\n<p>These changes are characterized by a <code>javax.swing.event.ListDataEvent<\/code>, which identifies the range of list indices that have been modified, added, or removed. JList&#8217;s ListUI is responsible for keeping the visual representation up to date with changes, by listening to the model. DefaultListModel class is used to maintain list elements by <code> JList<\/code> applications. This class implements the <code>ListModel<\/code> interface and also provides a <code>java.util.Vector <\/code>like API.<\/p>\n<p>Applications that need a more custom <code>ListModel<\/code> implementation may instead wish to subclass <code>AbstractListModel<\/code>, which provides basic support for managing and notifying listeners.<\/p>\n<h3>2.3. Creating a Model<\/h3>\n<p>There are three ways to create a list model:<\/p>\n<ul>\n<li>DefaultListModel \u2014 everything is pretty much taken care of for you. The examples in this page use DefaultListModel.<\/li>\n<li>AbstractListModel \u2014 you manage the data and invoke the &#8220;fire&#8221; methods. For this approach, you must subclass AbstractListModel and implement the getSize and getElementAt methods inherited from the ListModel interface.<\/li>\n<li>ListModel \u2014 you manage everything<\/li>\n<\/ul>\n<h3>2.4. Initializing a list<\/h3>\n<p><span style=\"text-decoration: underline;\"><em>SwingListExample.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">        listModel = new DefaultListModel();\r\n        listModel.addElement(\"Jasmine Mehra\");\r\n        listModel.addElement(\"Ankit Mishra\");\r\n        listModel.addElement(\"Madhuri Sanghvi\");\r\n        listModel.addElement(\"Alok Kumar\");\r\n        listModel.addElement(\"Rohit Bothra\");\r\n        listModel.addElement(\"Rahul Aggarwal\");\r\n        \r\n \r\n        \/\/Create the list and put it in a scroll pane.\r\n        list = new JList(listModel);\r\n        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r\n        list.setSelectedIndex(0);\r\n        list.addListSelectionListener(this);\r\n        list.setVisibleRowCount(5);\r\n        JScrollPane listScrollPane = new JScrollPane(list);\r\n\r\n<\/pre>\n<p>The above code creates and sets up the list. The code passes an array to the list&#8217;s constructor. The array is filled with strings. In our example, the strings happen to be person&#8217;s names.<\/p>\n<p>Other <code>JList<\/code> constructors let you initialize a list from a Vector or from an object that adheres to the <code>ListModel<\/code> interface. If you initialize a list with an array or vector, the constructor implicitly creates a default list model. The default list model is immutable \u2014 you cannot add, remove, or replace items in the list. To create a list whose items can be changed individually, set the list&#8217;s model to an instance of a mutable list model class, such as an instance of <code>DefaultListModel<\/code>. You can set a list&#8217;s model when you create the list or by calling the setModel method.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><code> setSelectionMode<\/code> specifies how many items the user can select, and whether they must be contiguous.<br \/>\n<code> setLayoutOrientation<\/code> lets the list display its data in multiple columns. The possible value such as, <code> JList.HORIZONTAL_WRAP <\/code> demonstrates that the list should display its items from left to right before wrapping to a new row. Another value that can be used is <code>JList.VERTICAL_WRAP <\/code>, which specifies that the data be displayed from top to bottom before wrapping to a new column.<\/p>\n<p><code>setVisibleRowCount(-1)<\/code> makes the list display the maximum number of items possible in the available space onscreen. Another popular use of <code>setVisibleRowCount<\/code> is to specify to the lists&#8217;s scroll pane how many rows the list prefers to display.<\/p>\n<h3>2.5. Selecting Items in a List<\/h3>\n<p>A list uses an instance of <code> ListSelectionModel <\/code> to manage its selection. By default, a list selection model allows any combination of items to be selected at a time. You can specify a different selection mode by calling the setSelectionMode method on the list. For example, SwingListExample set the selection mode to SINGLE_SELECTION (a constant defined by ListSelectionModel) so that only one item in the list can be selected. The three list selection modes are described below:<\/p>\n<ul>\n<li><b> SINGLE_SELECTION <\/b>: Only one item can be selected at a time. When the user selects an item, any previously selected item is deselected first.<\/li>\n<li><b>SINGLE_INTERVAL_SELECTION<\/b>: Multiple, contiguous items can be selected. When the user begins a new selection range, any previously selected items are deselected first.<\/li>\n<li><b>MULTIPLE_INTERVAL_SELECTION <\/b>: The default. Any combination of items can be selected. The user must explicitly deselect items.<\/li>\n<\/ul>\n<h2>3. Change in Values<\/h2>\n<p>No matter which selection mode your list uses, the list fires list selection events whenever the selection changes. You can process these events by adding a list selection listener to the list with the <code>addListSelectionListener<\/code> method. A list selection listener must implement one method: <code> valueChanged <\/code>. Here is the <code>valueChanged<\/code> method for the listener in SwingListExample.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SwingListExample.java<\/em><\/span><\/p>\n<pre class=\"brush:java\"> \/\/This method is required by ListSelectionListener.\r\n    public void valueChanged(ListSelectionEvent e) {\r\n        if (e.getValueIsAdjusting() == false) {\r\n \r\n            if (list.getSelectedIndex() == -1) {\r\n            \/\/No selection, disable fire button.\r\n                fireButton.setEnabled(false);\r\n \r\n            } else {\r\n            \/\/Selection, enable the fire button.\r\n                fireButton.setEnabled(true);\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n<h3>3.1 Adding and removing items to and from a List<\/h3>\n<p>The SwingListExample example creates a list whose contents can change. Here is the SwingListExample code that creates a mutable list model object, puts the initial items in it, and uses the list model to create a list:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SwingListExample.java<\/em><\/span><\/p>\n<pre class=\"brush:java\"> \r\n\r\n  listModel = new DefaultListModel();\r\n        listModel.addElement(\"Jasmine Mehra\");\r\n        listModel.addElement(\"Ankit Mishra\");\r\n        listModel.addElement(\"Madhuri Sanghvi\");\r\n        listModel.addElement(\"Alok Kumar\");\r\n        listModel.addElement(\"Rohit Bothra\");\r\n        listModel.addElement(\"Rahul Aggarwal\");\r\n \r\n        \/\/Create the list and put it in a scroll pane.\r\n        list = new JList(listModel);\r\n\r\n<\/pre>\n<p>This example uses an instance of <code>DefaultListModel<\/code>, a class provided by Swing. To create a <code>DefaulLIstModel<\/code> a program needs to explicitly mention it. If your requirement is not met through <code>DefaultListModel<\/code> then you can write a custom list model, which must adhere to the <code> ListModel<\/code> interface.<\/p>\n<p>Here is the actionPerformed method for the action listener shared by the Hire button and the text field:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SwingListExample.java<\/em><\/span><\/p>\n<pre class=\"brush:java\"> \r\n\r\n   public void actionPerformed(ActionEvent e) {\r\n            String name = employeeName.getText();\r\n \r\n            \/\/User didn't type in a unique name...\r\n            if (name.equals(\"\") || alreadyInList(name)) {\r\n                Toolkit.getDefaultToolkit().beep();\r\n                employeeName.requestFocusInWindow();\r\n                employeeName.selectAll();\r\n                return;\r\n            }\r\n \r\n            int index = list.getSelectedIndex(); \/\/get selected index\r\n            if (index == -1) { \/\/no selection, so insert at beginning\r\n                index = 0;\r\n            } else {           \/\/add after the selected item\r\n                index++;\r\n            }\r\n \r\n            listModel.insertElementAt(employeeName.getText(), index);\r\n            \/\/If we just wanted to add to the end, we'd do this:\r\n            \/\/listModel.addElement(employeeName.getText());\r\n \r\n            \/\/Reset the text field.\r\n            employeeName.requestFocusInWindow();\r\n            employeeName.setText(\"\");\r\n \r\n            \/\/Select the new item and make it visible.\r\n            list.setSelectedIndex(index);\r\n            list.ensureIndexIsVisible(index);\r\n        }\r\n<\/pre>\n<p>This code uses the list model&#8217;s insertElementAt method to insert the new name after the current selection or, if no selection exists, at the beginning of the list. If you just wish to add to the end of the list, you can use DefaultListModel&#8217;s addElement method instead.<br \/>\nWhenever items are added to, removed from, or modified in a list, the list model fires list data events.<\/p>\n<p>The following code snippet shows the <code> actionPerformed<\/code> method for the action listener registered on the Fire button. removes method is used to remove the selected item from the list. Fire button is disabled if the list is empty.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SwingListExample.java<\/em><\/span><\/p>\n<pre class=\"brush:java\"> \r\n\r\n public void actionPerformed(ActionEvent e) {\r\n            \/\/This method can be called only if\r\n            \/\/there's a valid selection\r\n            \/\/so go ahead and remove whatever's selected.\r\n            int index = list.getSelectedIndex();\r\n            listModel.remove(index);\r\n \r\n            int size = listModel.getSize();\r\n \r\n            if (size == 0) { \/\/Nobody's left, disable firing.\r\n                fireButton.setEnabled(false);\r\n \r\n            } else { \/\/Select an index.\r\n                if (index == listModel.getSize()) {\r\n                    \/\/removed item in last position\r\n                    index--;\r\n                }\r\n \r\n                list.setSelectedIndex(index);\r\n                list.ensureIndexIsVisible(index);\r\n            }\r\n        }\r\n\r\n<\/pre>\n<h3>3.2 List API<\/h3>\n<p>The following tables list the commonly used <code>JList<\/code> constructors and methods. Much of the operation of a list is managed by other objects. The items in the list are managed by a list model object, the selection is managed by a list selection model object, and most programs put a list in a scroll panel to handle scrolling.<\/p>\n<p>The API for using lists falls into these categories:<\/p>\n<h4>3.2.1 Initializing List Data<\/h4>\n<ul>\n<li><code>JList(ListModel)<\/code>,<code>JList(Object[])<\/code>,<code>JList(Vector)<\/code><code>JList()<\/code>: Create a list with the initial list items specified. The second and third constructors implicitly create an immutable <code>ListModel<\/code> you should not subsequently modify the passed-in array or Vector.<\/li>\n<li><code>void setModel(ListModel)<\/code>,<code>ListModel getModel()<\/code>: Set or get the model that contains the contents of the list.<\/li>\n<li><code>void setListData(Object[])<\/code>,<code>void setListData(Vector)<\/code>: Set the items in the list. These methods implicitly create an immutable <code>ListModel<\/code>.<\/li>\n<\/ul>\n<h4>3.2.2 Displaying the List<\/h4>\n<ul>\n<li><code>void setVisibleRowCount(int)<\/code>,<code>int getVisibleRowCount()<\/code>: Set or get the visibleRowCount property. For a VERTICAL layout orientation, this sets or gets the preferred number of rows to display without requiring scrolling. For the HORIZONTAL_WRAP or VERTICAL_WRAP layout orientations, it defines how the cells wrap. See the setLayoutOrientation(int) for more information. The default value of this property is VERTICAL.<\/li>\n<li><code>void setLayoutOrientation(int)<\/code>,<code>int getLayoutOrientation()<\/code>: Set or get the way list cells are laid out. The possible layout formats are specified by the JList-defined values VERTICAL (a single column of cells; the default), HORIZONTAL_WRAP (&#8220;newspaper&#8221; style with the content flowing horizontally then vertically), and VERTICAL_WRAP (&#8220;newspaper&#8221; style with the content flowing vertically then horizontally).<\/li>\n<li><code>int getFirstVisibleIndex()<\/code>,<code>int getLastVisibleIndex()<\/code>: Get the index of the first or last visible item.<\/li>\n<li><code>void ensureIndexIsVisible(int)<\/code>: Scroll so that the specified index is visible within the viewport that this list is in.<\/li>\n<\/ul>\n<p>Similarly, there are methods and constructors for other 2 categories too.<\/p>\n<ul>\n<li>Managing the List&#8217;s Selection<\/li>\n<li>Managing List Data<\/li>\n<\/ul>\n<h2>4. Code &amp; Output<\/h2>\n<p>The upper sections described how an item can be added or removed to or from the list at the runtime.<br \/>\nIn this example we have created 2 buttons Hire and Fire. Hire adds an element at runtime at a specified position whereas, Fire removes an element from the specified position.<\/p>\n<p>After execution of code output will look like the one below.<\/p>\n<p><figure id=\"attachment_38693\" aria-describedby=\"caption-attachment-38693\" style=\"width: 859px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-38693\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L1.jpg\" alt=\"JAVA Swing List\" width=\"859\" height=\"656\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L1.jpg 859w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L1-300x229.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L1-768x587.jpg 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/a><figcaption id=\"caption-attachment-38693\" class=\"wp-caption-text\">JAVA Swing List<\/figcaption><\/figure><\/p>\n<p>If you enter a text in the textbox it will enable the Hire button and output will look like the one below.<\/p>\n<p><figure id=\"attachment_38695\" aria-describedby=\"caption-attachment-38695\" style=\"width: 856px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-38695\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L2.jpg\" alt=\"JAVA Swing List\" width=\"856\" height=\"665\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L2.jpg 856w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L2-300x233.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/L2-768x597.jpg 768w\" sizes=\"(max-width: 856px) 100vw, 856px\" \/><\/a><figcaption id=\"caption-attachment-38695\" class=\"wp-caption-text\">JAVA Swing List<\/figcaption><\/figure><\/p>\n<h2>5. Download<\/h2>\n<p>This was an example of creation of swing JAVA List.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/06\/SwingListExample.zip\"><strong>SwingListExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more elements. Lists can have many items, so they are often put in scroll panes. A separate model, ListModel, maintains the contents of the list. An array of objects can &hellip;<\/p>\n","protected":false},"author":98,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[],"class_list":["post-38669","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-swing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JAVA Swing List Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JAVA Swing List Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/jyoti.jha.9256\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-28T12:00:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jyoti Jha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jyoti Jha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/\"},\"author\":{\"name\":\"Jyoti Jha\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7\"},\"headline\":\"JAVA Swing List Example\",\"datePublished\":\"2016-06-28T12:00:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/\"},\"wordCount\":1477,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"articleSection\":[\"swing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/\",\"name\":\"JAVA Swing List Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2016-06-28T12:00:03+00:00\",\"description\":\"1. Introduction JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Desktop Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"swing\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JAVA Swing List Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7\",\"name\":\"Jyoti Jha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg\",\"caption\":\"Jyoti Jha\"},\"description\":\"Jyoti is a tech enthusiast and is an avid programmer. She holds a post graduation degree in (M.Tech) Computer Science Engineering from Thapar Univeristy, Patiala, India. Post her graduate studies, she has worked in Software companies such as SLK Software and Aricent, India as Software Engineer in various projects primarily in the field of Requirement analysis and design, implementing new algorithms in C++ and JAVA used in ISDN network and designing databases and. She is inquisitive about socio economic reforms as well as advancement in technical fronts and keep herself informed with TED talks and various blogs.\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\/\",\"https:\/\/www.facebook.com\/jyoti.jha.9256\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/jyoti-jha\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JAVA Swing List Example - Java Code Geeks","description":"1. Introduction JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/","og_locale":"en_US","og_type":"article","og_title":"JAVA Swing List Example - Java Code Geeks","og_description":"1. Introduction JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/jyoti.jha.9256","article_published_time":"2016-06-28T12:00:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Jyoti Jha","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Jyoti Jha","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/"},"author":{"name":"Jyoti Jha","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7"},"headline":"JAVA Swing List Example","datePublished":"2016-06-28T12:00:03+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/"},"wordCount":1477,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","articleSection":["swing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/","name":"JAVA Swing List Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2016-06-28T12:00:03+00:00","description":"1. Introduction JList is a swing component through which we can display the list of objects. This swing component allows user to select one or more","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/java-swing-list-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Desktop Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/"},{"@type":"ListItem","position":4,"name":"swing","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/"},{"@type":"ListItem","position":5,"name":"JAVA Swing List Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7dcd033e37def0d21806e891845d89b7","name":"Jyoti Jha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/05\/Jyoti-Jha-96x96.jpg","caption":"Jyoti Jha"},"description":"Jyoti is a tech enthusiast and is an avid programmer. She holds a post graduation degree in (M.Tech) Computer Science Engineering from Thapar Univeristy, Patiala, India. Post her graduate studies, she has worked in Software companies such as SLK Software and Aricent, India as Software Engineer in various projects primarily in the field of Requirement analysis and design, implementing new algorithms in C++ and JAVA used in ISDN network and designing databases and. She is inquisitive about socio economic reforms as well as advancement in technical fronts and keep herself informed with TED talks and various blogs.","sameAs":["https:\/\/www.javacodegeeks.com\/","https:\/\/www.facebook.com\/jyoti.jha.9256"],"url":"https:\/\/examples.javacodegeeks.com\/author\/jyoti-jha\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/38669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/98"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=38669"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/38669\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=38669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=38669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=38669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}