JList:addListSelectionListener(ListSelectionListener l)

JList:addListSelectionListener(ListSelectionListener l)

JList-addListSelectionListener-example
To determine if elements in a JList have been selected,you have to add JList:addListSelectionListener
Previous post we added ActionListener to JList


JList:addListSelectionListener Example

[
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.UIManager;

import java.util.ArrayList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import javax.swing.JLabel;
import javax.swing.JButton;

public class JListExample extends JFrame implements ListSelectionListener{
    public JList<String> list;
    public JLabel label;
    JListExample()
    {
        super("JFrame Example");
        try        {
            UIManager.setLookAndFeel
("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
        }
        catch(Exception e)
        {

        }
        ArrayList arr=new ArrayList();
        arr.add("Java");
        arr.add("C#");
        arr.add("C++");

        list=new JList(arr.toArray());
        list.setBounds(50, 50, 100, 100);
        add(list);
        list.addListSelectionListener(this);

        setSize(400,400);
        setLayout(null);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }
    public void valueChanged(ListSelectionEvent event)
    {
        if(event.getValueIsAdjusting())
            return;

        System.out.println("Value changed from " +event.getLastIndex() + 
" to " +event.getFirstIndex());

    }
    public static void main(String args[])
    {
        new JListExample();
    }

}
]

JList:addListSelectionListener Output

JList-addListSelectionListener-example2


Below Code sets Application look and feel to WindowsClassicLookAndFeel
[
 try        {
            UIManager.setLookAndFeel
("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
        }
        catch(Exception e)
        {
]

 setDefaultCloseOperation(EXIT_ON_CLOSE) ensures the application exits when the
 close button is clicked


See also : Java JTable

COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: JList:addListSelectionListener(ListSelectionListener l)
JList:addListSelectionListener(ListSelectionListener l)
JList:addListSelectionListener(ListSelectionListener l)
https://4.bp.blogspot.com/-Fkadb2uFTI0/WMZgBByh4tI/AAAAAAAAHKE/8JTu4TLQc0Miyl49GKEdgoHGHLGr3FpLACLcB/s200/JList-addListSelectionListener-example-min.PNG
https://4.bp.blogspot.com/-Fkadb2uFTI0/WMZgBByh4tI/AAAAAAAAHKE/8JTu4TLQc0Miyl49GKEdgoHGHLGr3FpLACLcB/s72-c/JList-addListSelectionListener-example-min.PNG
Java Codes
http://www.download-all.net/2017/03/jlistaddlistselectionlistenerlistselect.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/03/jlistaddlistselectionlistenerlistselect.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy