How can I display a string provided with an arraylist in a combobox?

Asked

Viewed 53 times

-1

Good morning. I have a record of films, which are found in an arraylist. These films have a name, director etc. Since this array is public, I would like to display, in another interface, the name of each of these films in a combobox. How could I do that?

I’m a beginner and I use netbeans.

1 answer

0

I made the biggest mooring here, it was like this :

private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
     String[] nomesFilmes;
     nomesFilmes= new String[20];
       for(int i=0;i<Cinema.filmes.size();i++){
           if(Cinema.filmes.get(i)!=null){
              nomesFilmes[i]=Cinema.filmes.get(i).getNome(); 
           }
        }
   DefaultComboBoxModel nomesF= new DefaultComboBoxModel(nomesFilmes);
   filmes.setModel(nomesF);

    }                                 

Now it’s like this:

private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
     String[] nomesFilmes;
     nomesFilmes= new String[20];
       for(int i=0;i<Cinema.filmes.size();i++){
           if(Cinema.filmes.get(i)!=null){
             filmes.addItem(Cinema.filmes.get(i).getNome());
           }
        }
    }   

Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.