Java JList.getModel()

Java JList.getModel()

Java JList.getModel()  has below Syntax
[
public ListModel < E > getModel()
]


Java JList.getModel() Example

[
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JavaJListExample extends JFrame  implements ActionListener{
    public JList list;
    public JButton button;
    JavaJListExample()
    {
        super("JList");

        String language []={"Java","C++","PHP","Python","C#"};
        list=new JList();
        list.setListData(language);
        list.setVisibleRowCount(3);

        JScrollPane pane=new JScrollPane(list);
        pane.setBounds(50, 50, 100, 50);
        add(pane);

        button=new JButton("Click me");
        button.setBounds(50, 150, 100, 30);

        add(button);
        button.addActionListener(this);

        setSize(400,400);
        setLayout(null);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }

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

    }
    public void actionPerformed(ActionEvent event)
    {

        ListModel m=list.getModel();
        System.out.println("The ListModel is " +m);

    }
}
]

Java JList.getModel Code Explanation

When the JButton is clicked by the user, Abstract [public void actionPerformed(ActionEvent event)
    {

        ListModel m=list.getModel();
        System.out.println("The ListModel is " +m);
    }]

ActionListener method is performed.We get list model using getModel() method and store it as variable M.

[ JScrollPane pane=new JScrollPane(list);] code adds scroll ability to the JList.

[ setDefaultCloseOperation(EXIT_ON_CLOSE);] exits application when the close button is clicked.

Above class extends JFrame i.e it inherits all JFrame methods like setLayout,setSize etc

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: Java JList.getModel()
Java JList.getModel()
Java JList.getModel()
Java Codes
http://www.download-all.net/2017/03/java-jlistgetmodel.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/03/java-jlistgetmodel.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