{"id":23138,"date":"2015-05-12T11:00:34","date_gmt":"2015-05-12T08:00:34","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=23138"},"modified":"2015-06-06T17:02:07","modified_gmt":"2015-06-06T14:02:07","slug":"java-jlist-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/","title":{"rendered":"Java JList Example"},"content":{"rendered":"<p>In this example we are going to demonstrate how to use Java Swing <code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>, <code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>\u00a0is a Swing component with which we can display a list of elements. This component also allows the user to select one or more elements visually. This article shows how to work with\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> features using a simple example where we build a GUI with a\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> to show a list of employee names and let us add\/remove a single name to\/from the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> dynamically.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>1. Swing JList:<\/h2>\n<p>We create a custom\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> <code>SwingJList.java<\/code> where we can initialize the data model, customize the selection mode and enable scrolling.<\/p>\n<ol>\n<li>\n<h4>JList Data Model:<\/h4>\n<p>As with other Swing components, the data for a\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> is held in a model. This is represented by <code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/ListModel.html\" target=\"_blank\">ListModel<\/a><\/code> interface in the Swing API. The API provides a default implementation of this class named <code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/DefaultListModel.html\" target=\"_blank\">DefaultListModel<\/a><\/code>. So, We create an instance of the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/DefaultListModel.html\" target=\"_blank\">DefaultListModel<\/a><\/code> class by declaring it as accepting <code>T<\/code>\u00a0as a parameterized raw type using Java Generics. Also, we added two additional methods <code>addElement(T element)<\/code> and <code>removeElement(T element)<\/code> which implicitly use\u00a0<code><span class=\"memberNameLink\"><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/DefaultListModel.html#add-int-E-\">add<\/a><\/span>(int\u00a0index, <a title=\"type parameter in DefaultListModel\" href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/DefaultListModel.html\">E<\/a>\u00a0element)<\/code> and\u00a0<code><span class=\"memberNameLink\"><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/DefaultListModel.html#removeElement-java.lang.Object-\">removeElement<\/a><\/span>(<a title=\"class in java.lang\" href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/lang\/Object.html\">Object<\/a>\u00a0obj)<\/code> to let us add\/remove elements to\/from the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> model.<\/p>\n<pre class=\"brush:java\">public SwingJList(List&lt;T&gt; listData) {\r\n\t\/\/ Create a JList data model\r\n\tsuper(new DefaultListModel&lt;T&gt;());\r\n\tlistData.forEach(element -&gt; addElement(element));\r\n}\r\n\r\npublic void addElement(T element) {\r\n\t((DefaultListModel&lt;T&gt;) getModel()).add(Constants.NEW_ELEMENT_IDX,\r\n\t\t\t\telement);\r\n}\r\n\r\npublic void removeElement(Object element) {\r\n\t((DefaultListModel&lt;T&gt;) getModel()).removeElement(element);\r\n}\r\n<\/pre>\n<\/li>\n<li>\n<h4>JList Selection Mode:<\/h4>\n<p>The\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> selection mode defines the way elements can be selected,\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> uses an instance of <code><a class=\"APILink\" href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/ListSelectionModel.html\" target=\"_blank\">ListSelectionModel<\/a><\/code> to manage its selection. By default, a\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> selection model is <code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/ListSelectionModel.html#MULTIPLE_INTERVAL_SELECTION\" target=\"_blank\">MULTIPLE_INTERVAL_SELECTION<\/a><\/code> but we\u00a0can specify a different selection mode by calling the <code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html#setSelectionModel-javax.swing.ListSelectionModel-\" target=\"_blank\">setSelectionMode<\/a><\/code> method on the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>. There are totally 3 selection modes available to be set for the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>:<\/p>\n<ol>\n<li><span style=\"text-decoration: underline\">Single Selection Mode<\/span>:<br \/>\nThis mode specifies that only a single item can be selected at any point of time, we can activate this mode as the following:<\/p>\n<pre class=\"brush:java\">setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r\n<\/pre>\n<p><figure id=\"attachment_24091\" aria-describedby=\"caption-attachment-24091\" style=\"width: 307px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/1single_selection_mode.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/1single_selection_mode.jpg\" alt=\"Figure 1: Single Selection Mode\" width=\"307\" height=\"251\" class=\"size-full wp-image-24091\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/1single_selection_mode.jpg 307w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/1single_selection_mode-300x245.jpg 300w\" sizes=\"(max-width: 307px) 100vw, 307px\" \/><\/a><figcaption id=\"caption-attachment-24091\" class=\"wp-caption-text\">Figure 1: Single Selection Mode<\/figcaption><\/figure><\/li>\n<li><span style=\"text-decoration: underline\">Single Interval Selection Mode<\/span>:<br \/>\nThis mode specifies that multiple items can be selected, but they have to be contiguous. Items can be selected contiguously by pressing down the shift key and selecting elements with the mouse, we can activate this mode as the following:<\/p>\n<pre class=\"brush:java\">setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);\r\n<\/pre>\n<p><figure id=\"attachment_24092\" aria-describedby=\"caption-attachment-24092\" style=\"width: 304px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/2single_interval_selection.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/2single_interval_selection.jpg\" alt=\"Figure 2: Single Interval Selection Mode\" width=\"304\" height=\"245\" class=\"size-full wp-image-24092\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/2single_interval_selection.jpg 304w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/2single_interval_selection-300x242.jpg 300w\" sizes=\"(max-width: 304px) 100vw, 304px\" \/><\/a><figcaption id=\"caption-attachment-24092\" class=\"wp-caption-text\">Figure 2: Single Interval Selection Mode<\/figcaption><\/figure><\/li>\n<li><span style=\"text-decoration: underline\">Multiple Interval Selection Mode<\/span>:<br \/>\nThis mode is the default mode. This mode specifies that multiple items can be selected and they may or may not be contiguous, we can activate this mode as the following:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);\r\n<\/pre>\n<p><figure id=\"attachment_24095\" aria-describedby=\"caption-attachment-24095\" style=\"width: 305px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3multiple_interval_selection.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3multiple_interval_selection.jpg\" alt=\"Figure 3: Multiple Interval Selection Mode\" width=\"305\" height=\"243\" class=\"size-full wp-image-24095\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3multiple_interval_selection.jpg 305w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3multiple_interval_selection-300x239.jpg 300w\" sizes=\"(max-width: 305px) 100vw, 305px\" \/><\/a><figcaption id=\"caption-attachment-24095\" class=\"wp-caption-text\">Figure 3: Multiple Interval Selection Mode<\/figcaption><\/figure><\/li>\n<\/ol>\n<\/li>\n<li>\n<h4>JList Scrolling:<\/h4>\n<p><code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> doesn&#8217;t support scrolling directly. To create a scrolling\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>, we have to add the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> to a <code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JScrollPane.html\" target=\"_blank\">JScrollPane<\/a><\/code>, as the following:<\/p>\n<pre class=\"brush:java\">JScrollPane listScrollPane = new JScrollPane(simpleSwingJList);\r\n<\/pre>\n<\/li>\n<\/ol>\n<p><em><span style=\"text-decoration: underline\">SwingJList.java<\/span>:<\/em><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\nimport java.util.List;\r\n\r\nimport javax.swing.DefaultListModel;\r\nimport javax.swing.JList;\r\nimport javax.swing.ListSelectionModel;\r\n\r\n\/**\r\n * @author ashraf\r\n * @param &lt;T&gt;\r\n *\r\n *\/\r\n@SuppressWarnings(\"serial\")\r\npublic class SwingJList&lt;T&gt; extends JList&lt;T&gt; {\r\n\r\n\tpublic SwingJList(List&lt;T&gt; listData) {\r\n\r\n\t\t\/\/ Create a JList data model\r\n\t\tsuper(new DefaultListModel&lt;T&gt;());\r\n\r\n\t\tlistData.forEach(element -&gt; addElement(element));\r\n\r\n\t\t\/\/ Set selection mode\r\n\t\tsetSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r\n\r\n\t}\r\n\r\n\tpublic void addElement(T element) {\r\n\t\t((DefaultListModel&lt;T&gt;) getModel()).add(Constants.NEW_ELEMENT_IDX,\r\n\t\t\t\telement);\r\n\t}\r\n\r\n\tpublic void removeElement(Object element) {\r\n\t\t((DefaultListModel&lt;T&gt;) getModel()).removeElement(element);\r\n\t}\r\n\r\n}\r\n<\/pre>\n<h2>2. JList Selection Listener:<\/h2>\n<p>The\u00a0<code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/event\/ListSelectionListener.html\" target=\"_blank\">ListSelectionListener<\/a><\/code> fires the event if the user selecting or deselecting an item. The below code registers a\u00a0<code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/event\/ListSelectionListener.html\" target=\"_blank\">ListSelectionListener<\/a><\/code> using the\u00a0<code><span class=\"memberNameLink\"><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html#addListSelectionListener-javax.swing.event.ListSelectionListener-\">addListSelectionListener<\/a><\/span>(<a title=\"interface in javax.swing.event\" href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/event\/ListSelectionListener.html\">ListSelectionListener<\/a>\u00a0listener)<\/code>\u00a0method. We use an anonymous inner class to implement the event listener interface. We implement the\u00a0<code><span class=\"memberNameLink\"><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/event\/ListSelectionListener.html#valueChanged-javax.swing.event.ListSelectionEvent-\">valueChanged<\/a><\/span>(<a title=\"class in javax.swing.event\" href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/event\/ListSelectionEvent.html\">ListSelectionEvent<\/a>\u00a0e)<\/code> method. We call the handy method\u00a0<code><span class=\"memberNameLink\"><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html#getSelectedValue--\">getSelectedValue<\/a><\/span>()<\/code>\u00a0on the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> instance which returns the current selected employee name, we simply show it in the input text box.<\/p>\n<pre class=\"brush:java\">swingJList.addListSelectionListener(new ListSelectionListener() {\r\n\t@Override\r\n\tpublic void valueChanged(ListSelectionEvent e) {\r\n\t\tif (!e.getValueIsAdjusting()) {\r\n\t\t\tString selectedName = swingJList.getSelectedValue();\r\n\t\t\tnameField.setText(selectedName);\r\n\t\t}\r\n\t}\r\n});\r\n<\/pre>\n<h2>3. Adding\/Removing JList Items:<\/h2>\n<p>We add\/remove items to\/from the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code> via Swing component event listeners, we just register an event listener to be notified when add or remove event happens. we create the following two <code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/event\/ActionListener.html\" target=\"_blank\">ActionListener<\/a><\/code> where we add one on the <code>addButton<\/code> and the other on the <code>deleteButton<\/code> <code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JButton.html\" target=\"_blank\">JButton<\/a><\/code>.<\/p>\n<ol>\n<li><span style=\"text-decoration: underline\">Add Action Listener<\/span>:<br \/>\nWe create <code>addButton<\/code> <code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JButton.html\" target=\"_blank\">JButton<\/a><\/code> to add a new employee name to the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>, we register an\u00a0<code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/event\/ActionListener.html\" target=\"_blank\">ActionListener<\/a><\/code>, then we implement the\u00a0<code><span class=\"memberNameLink\"><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/event\/ActionListener.html#actionPerformed-java.awt.event.ActionEvent-\">actionPerformed<\/a><\/span>(<a title=\"class in java.awt.event\" href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/event\/ActionEvent.html\">ActionEvent<\/a>\u00a0e)<\/code>\u00a0method to add a single employee name to our employees list. Now, we can write any employee name in the input text box and click the <code>Add Employee<\/code> button to be added to the employees list.<\/p>\n<pre class=\"brush:java\">JButton addButton = new JButton(\"Add Employee\");\r\naddButton.addActionListener(new ActionListener() {\r\n\tpublic void actionPerformed(ActionEvent e) {\r\n\t\tString name = nameField.getText();\r\n\t\tif (name != null &amp;&amp; !\"\".equals(name)) {\r\n\t\t\tswingJList.addElement(name);\r\n\t\t} else {\r\n\t\t\tJOptionPane.showMessageDialog(null,\r\n\t\t\t\t\t\"Employee name is empty\", \"Error\",\r\n\t\t\t\t\tJOptionPane.ERROR_MESSAGE);\r\n\t\t}\r\n\t}\r\n});\r\n<\/pre>\n<\/li>\n<li><span style=\"text-decoration: underline\">Delete Action Listener<\/span>:<br \/>\nWe create <code>deleteButton<\/code> <code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JButton.html\" target=\"_blank\">JButton<\/a><\/code> to remove selected employee name from the\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>, we register an\u00a0<code><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/event\/ActionListener.html\" target=\"_blank\">ActionListener<\/a><\/code>, then we implement the\u00a0<code><span class=\"memberNameLink\"><a href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/event\/ActionListener.html#actionPerformed-java.awt.event.ActionEvent-\">actionPerformed<\/a><\/span>(<a title=\"class in java.awt.event\" href=\"http:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/awt\/event\/ActionEvent.html\">ActionEvent<\/a>\u00a0e)<\/code>\u00a0method to remove a single employee name from our employees list. Now, we can select a single employee name and click the <code>Delete Employee<\/code> button to be removed from the employees list.<\/p>\n<pre class=\"brush:java\">JButton deleteButton = new JButton(\"Delete Employee\");\r\ndeleteButton.addActionListener(new ActionListener() {\r\n\tpublic void actionPerformed(ActionEvent e) {\r\n\t\tString name = nameField.getText();\r\n\t\tif (name != null &amp;&amp; !\"\".equals(name)) {\r\n\t\t\tswingJList.removeElement(name);\r\n\t\t} else {\r\n\t\t\tJOptionPane.showMessageDialog(null,\r\n\t\t\t\t\t\"Please, select employee name from the list\",\r\n\t\t\t\t\t\"Warning\", JOptionPane.WARNING_MESSAGE);\r\n\t\t}\r\n\t}\r\n});\r\n<\/pre>\n<\/li>\n<\/ol>\n<h2>4. JList Demo:<\/h2>\n<p>We create <code>SwingJListDemo.java<\/code> class to test our example. Also, we add a supplementary <code>Constants.java<\/code> class contains constants used through our\u00a0code.<\/p>\n<p><em><span style=\"text-decoration: underline\">SwingJListDemo.java<\/span>:<\/em><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\nimport java.awt.Dimension;\r\nimport java.awt.event.ActionEvent;\r\nimport java.awt.event.ActionListener;\r\nimport java.util.Arrays;\r\n\r\nimport javax.swing.BorderFactory;\r\nimport javax.swing.JButton;\r\nimport javax.swing.JFrame;\r\nimport javax.swing.JOptionPane;\r\nimport javax.swing.JPanel;\r\nimport javax.swing.JScrollPane;\r\nimport javax.swing.JSplitPane;\r\nimport javax.swing.JTextField;\r\nimport javax.swing.SwingUtilities;\r\nimport javax.swing.UIManager;\r\nimport javax.swing.UIManager.LookAndFeelInfo;\r\nimport javax.swing.border.TitledBorder;\r\nimport javax.swing.event.ListSelectionEvent;\r\nimport javax.swing.event.ListSelectionListener;\r\n\r\n\/**\r\n * @author ashraf_sarhan\r\n * \r\n *\/\r\npublic class SwingJListDemo {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tSwingUtilities.invokeLater(new Runnable() {\r\n\t\t\tpublic void run() {\r\n\t\t\t\ttry {\r\n\t\t\t\t\tsetLookAndFeel(Constants.NIMBUS_LF);\r\n\t\t\t\t\tcreateAndShowGUI();\r\n\t\t\t\t} catch (Exception e) {\r\n\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n\r\n\tpublic static void createAndShowGUI() throws Exception {\r\n\r\n\t\tJFrame frame = new JFrame(\"Swing JList Demo\");\r\n\t\tframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r\n\r\n\t\t\/\/ Create JList with a List of String names\r\n\t\tSwingJList&lt;String&gt; swingJList = new SwingJList&lt;&gt;(\r\n\t\t\t\tArrays.asList(Constants.LIST_DATA));\r\n\r\n\t\tJTextField nameField = new JTextField(26);\r\n\r\n\t\t\/\/ Adding a list selection listener\r\n\t\tswingJList.addListSelectionListener(new ListSelectionListener() {\r\n\t\t\t@Override\r\n\t\t\tpublic void valueChanged(ListSelectionEvent e) {\r\n\t\t\t\tif (!e.getValueIsAdjusting()) {\r\n\t\t\t\t\tString selectedName = swingJList.getSelectedValue();\r\n\t\t\t\t\tnameField.setText(selectedName);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\t\/\/ Create an action listener to add a new item to the List\r\n\t\tJButton addButton = new JButton(\"Add Employee\");\r\n\t\taddButton.addActionListener(new ActionListener() {\r\n\t\t\tpublic void actionPerformed(ActionEvent e) {\r\n\t\t\t\tString name = nameField.getText();\r\n\t\t\t\tif (name != null &amp;&amp; !\"\".equals(name)) {\r\n\t\t\t\t\tswingJList.addElement(name);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tJOptionPane.showMessageDialog(null,\r\n\t\t\t\t\t\t\t\"Employee name is empty\", \"Error\",\r\n\t\t\t\t\t\t\tJOptionPane.ERROR_MESSAGE);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\t\/\/ Create an action listener to remove existed item from the List\r\n\t\tJButton deleteButton = new JButton(\"Delete Employee\");\r\n\t\tdeleteButton.addActionListener(new ActionListener() {\r\n\t\t\tpublic void actionPerformed(ActionEvent e) {\r\n\t\t\t\tString name = nameField.getText();\r\n\t\t\t\tif (name != null &amp;&amp; !\"\".equals(name)) {\r\n\t\t\t\t\tswingJList.removeElement(name);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tJOptionPane.showMessageDialog(null,\r\n\t\t\t\t\t\t\t\"Please, select employee name from the list\",\r\n\t\t\t\t\t\t\t\"Warning\", JOptionPane.WARNING_MESSAGE);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t});\r\n\r\n\t\t\/\/ Put the JList in a JScrollPane to handle scrolling\r\n\t\tJScrollPane listScrollPane = new JScrollPane(swingJList);\r\n\t\tlistScrollPane.setPreferredSize(new Dimension(250, 200));\r\n\r\n\t\tlistScrollPane.setBorder(BorderFactory.createTitledBorder(\r\n\t\t\t\tBorderFactory.createEtchedBorder(), \"Employees List\",\r\n\t\t\t\tTitledBorder.CENTER, TitledBorder.TOP));\r\n\r\n\t\t\/\/ Create a control panel\r\n\t\tJPanel buttonPane = new JPanel();\r\n\t\tbuttonPane.add(nameField);\r\n\t\tbuttonPane.add(addButton);\r\n\t\tbuttonPane.add(deleteButton);\r\n\r\n\t\tJSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,\r\n\t\t\t\tlistScrollPane, buttonPane);\r\n\t\tsplitPane.setDividerLocation(250);\r\n\t\tsplitPane.setEnabled(false);\r\n\r\n\t\tframe.add(splitPane);\r\n\t\tframe.pack();\r\n\t\tframe.setLocationRelativeTo(null);\r\n\t\tframe.setVisible(true);\r\n\t}\r\n\r\n\tpublic static void setLookAndFeel(String lf) throws Exception {\r\n\t\t\/\/ Set Nimbus as L&amp;F\r\n\t\ttry {\r\n\t\t\tfor (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {\r\n\t\t\t\tif (lf.equals(info.getName())) {\r\n\t\t\t\t\tUIManager.setLookAndFeel(info.getClassName());\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t} catch (Exception e) {\r\n\t\t\t\/\/ If Nimbus is not available, you can set the GUI the system\r\n\t\t\t\/\/ default L&amp;F.\r\n\t\t\tUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r\n\t\t}\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p><em><span style=\"text-decoration: underline\">Constants.java<\/span>:<\/em><\/p>\n<pre class=\"brush:java\">package com.jcg;\r\n\r\n\/**\r\n * @author ashraf_sarhan\r\n * \r\n *\/\r\npublic class Constants {\r\n\r\n\tpublic static final String NIMBUS_LF = \"Nimbus\";\r\n\r\n\tpublic static final String[] LIST_DATA = { \"Ashraf Sarhan\", \"Sara Mohamed\",\r\n\t\t\t\"Esraa Ahmed\", \"Ghada Mohamed\", \"Dalia Osama\", \"Amira Mohamed\",\r\n\t\t\t\"Sama Karim\", \"Nada Ahmed\", \"Ahmed Farrag\", \"Mohamed Senussi\",\r\n\t\t\t\"Nehal Taha\", \"Ahmed Sarhan\", \"Khaled Mohamed\" };\r\n\r\n\tpublic static final int NEW_ELEMENT_IDX = 0;\r\n\r\n}\r\n<\/pre>\n<p><em><span style=\"text-decoration: underline\">Output<\/span>:<\/em><br \/>\n<figure id=\"attachment_24093\" aria-describedby=\"caption-attachment-24093\" style=\"width: 829px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3swing_jlist_demo.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3swing_jlist_demo.jpg\" alt=\"Figure 4: Swing JList Demo\" width=\"829\" height=\"227\" class=\"size-full wp-image-24093\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3swing_jlist_demo.jpg 829w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/3swing_jlist_demo-300x82.jpg 300w\" sizes=\"(max-width: 829px) 100vw, 829px\" \/><\/a><figcaption id=\"caption-attachment-24093\" class=\"wp-caption-text\">Figure 4: Swing JList Demo<\/figcaption><\/figure><\/p>\n<h2>5. Download the Source Code of this example:<\/h2>\n<p>This was an example on how to use Java Swing\u00a0<code><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JList.html\" target=\"_blank\">JList<\/a><\/code>.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a title=\"Swing JList Example Code\" href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/05\/swingjlist-example-code.zip\" target=\"_blank\"><strong>SwingJListExampleCode.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going to demonstrate how to use Java Swing JList, JList\u00a0is a Swing component with which we can display a list of elements. This component also allows the user to select one or more elements visually. This article shows how to work with\u00a0JList features using a simple example where we build &hellip;<\/p>\n","protected":false},"author":24,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[145],"tags":[],"class_list":["post-23138","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jlist"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java JList Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example we are going to demonstrate how to use Java Swing JList, JList\u00a0is a Swing component with which we can display a list of elements. This\" \/>\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\/jlist\/java-jlist-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java JList Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example we are going to demonstrate how to use Java Swing JList, JList\u00a0is a Swing component with which we can display a list of elements. This\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-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\/ashraf.sar7an\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-12T08:00:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-06-06T14:02:07+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=\"Ashraf Sarhan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/ashraf_sarhan\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashraf Sarhan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 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\/jlist\/java-jlist-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/\"},\"author\":{\"name\":\"Ashraf Sarhan\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/553eb8f56e9ffb76e6bcc85d6157fc91\"},\"headline\":\"Java JList Example\",\"datePublished\":\"2015-05-12T08:00:34+00:00\",\"dateModified\":\"2015-06-06T14:02:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/\"},\"wordCount\":678,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"articleSection\":[\"JList\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/\",\"name\":\"Java JList Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2015-05-12T08:00:34+00:00\",\"dateModified\":\"2015-06-06T14:02:07+00:00\",\"description\":\"In this example we are going to demonstrate how to use Java Swing JList, JList\u00a0is a Swing component with which we can display a list of elements. This\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-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\/jlist\/java-jlist-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\":\"JList\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/jlist\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Java JList 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\/553eb8f56e9ffb76e6bcc85d6157fc91\",\"name\":\"Ashraf Sarhan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg\",\"caption\":\"Ashraf Sarhan\"},\"description\":\"Ashraf Sarhan is a passionate software engineer, an open source enthusiast, has a Bsc. degree in Computer and Information Systems from Alexandria University. He is experienced in building large, scalable and distributed enterprise applications\/service in multiple domains. He also has a keen interest in JavaEE, SOA, Agile and Big Data technologies.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\",\"https:\/\/www.facebook.com\/ashraf.sar7an\",\"https:\/\/eg.linkedin.com\/in\/ashrafsarhan\",\"https:\/\/x.com\/http:\/\/twitter.com\/ashraf_sarhan\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/ashraf-sarhan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java JList Example - Java Code Geeks","description":"In this example we are going to demonstrate how to use Java Swing JList, JList\u00a0is a Swing component with which we can display a list of elements. This","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\/jlist\/java-jlist-example\/","og_locale":"en_US","og_type":"article","og_title":"Java JList Example - Java Code Geeks","og_description":"In this example we are going to demonstrate how to use Java Swing JList, JList\u00a0is a Swing component with which we can display a list of elements. This","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/ashraf.sar7an","article_published_time":"2015-05-12T08:00:34+00:00","article_modified_time":"2015-06-06T14:02:07+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":"Ashraf Sarhan","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/ashraf_sarhan","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ashraf Sarhan","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/"},"author":{"name":"Ashraf Sarhan","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/553eb8f56e9ffb76e6bcc85d6157fc91"},"headline":"Java JList Example","datePublished":"2015-05-12T08:00:34+00:00","dateModified":"2015-06-06T14:02:07+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/"},"wordCount":678,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","articleSection":["JList"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/","name":"Java JList Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2015-05-12T08:00:34+00:00","dateModified":"2015-06-06T14:02:07+00:00","description":"In this example we are going to demonstrate how to use Java Swing JList, JList\u00a0is a Swing component with which we can display a list of elements. This","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/desktop-java\/swing\/jlist\/java-jlist-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\/jlist\/java-jlist-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":"JList","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/jlist\/"},{"@type":"ListItem","position":6,"name":"Java JList 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\/553eb8f56e9ffb76e6bcc85d6157fc91","name":"Ashraf Sarhan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg","caption":"Ashraf Sarhan"},"description":"Ashraf Sarhan is a passionate software engineer, an open source enthusiast, has a Bsc. degree in Computer and Information Systems from Alexandria University. He is experienced in building large, scalable and distributed enterprise applications\/service in multiple domains. He also has a keen interest in JavaEE, SOA, Agile and Big Data technologies.","sameAs":["http:\/\/www.javacodegeeks.com","https:\/\/www.facebook.com\/ashraf.sar7an","https:\/\/eg.linkedin.com\/in\/ashrafsarhan","https:\/\/x.com\/http:\/\/twitter.com\/ashraf_sarhan"],"url":"https:\/\/examples.javacodegeeks.com\/author\/ashraf-sarhan\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23138","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\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=23138"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23138\/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=23138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=23138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=23138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}