Como preencher JList?

3 respostas
D
StringTokenizer ip = new StringTokenizer(cfg.lerDavidProperties("ip"), ",");
        Collection<String> ipList = new ArrayList<String>();
        String[] teste = null;
        while(ip.hasMoreTokens()){
        	ipList.add(ip.nextToken().trim());
        }
        teste = ipList.toArray(new String[ipList.size()]);
       
        listIPCadastrados.setModel(new javax.swing.AbstractListModel() {

      	
        	String[] strings = { **aqui seria onde entram os dados que foram carregados** };
             	
        	
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

Alguem sabe como que eu faço para preencher o atributo strings pq não estou conseguindo!

3 Respostas

R

De uma olhada neste site, ele irá te ajudar:
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

D

eu já tinha olhado essa documentação e não me ajudou!!

D

Problema resolvido:

StringTokenizer ip = new StringTokenizer(cfg.lerMonitorProperties("ip"), ",");
        
        Collection<String> ipList = new ArrayList<String>();
        
        while(ip.hasMoreTokens()){
        	ipList.add(ip.nextToken().trim());
        }
      
        DefaultListModel dlm = new DefaultListModel();    
        
        Iterator it = ipList.iterator();
        while(it.hasNext()) {
        	dlm.addElement(it.next());
        }
        listIPCadastrados.setModel(dlm);
Criado 21 de fevereiro de 2007
Ultima resposta 22 de fev. de 2007
Respostas 3
Participantes 2