i have a JList component should me show a certain number of String when i click a jbutton component. I add every item (String) into a DefaultListModel and then pass it to the Jlist component in this way:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel<String> listModel = new DefaultListModel<>();
listModel.addElement("USA");
listModel.addElement("India");
listModel.addElement("Vietnam");
listModel.addElement("Canada");
listModel.addElement("Denmark");
listModel.addElement("France");
listModel.addElement("Great Britain");
listModel.addElement("Japan");
//create the list
countryList = new JList<>(listModel);
}
where JList component is defined in the following ways:
private JList<String> countryList;
when i run program my JList is empty and doesn't show me elements i added. If i use this command:
System.out.println(countryList.getModel());
for testing if items are added into the DefaultListModel component i can see them. Why JList component doesn't shows me elements? Thanks