Hashmap und JList

kahta

Grünschnabel
Hallo

ich möchte den Inhalt einer Hashmap in eine JList übernehmen.
Wie mach ich das am besten ? Den Schlüßelwert würde ich weglassen...
Muss der Inhalt erst in einen Vector ?
Weil damit geht es ja ohne Probleme die JList zu füllen
Vielen Dank
 
Hallo!

Schau mal hier:
Code:
/*
 * Created on 09.01.2005@16:18:08
 *
 * TODO Licence info
 */
package de.tutorials;

import java.awt.BorderLayout;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.ListModel;

/**
 * @author Administrator
 * 
 * TODO Explain me...
 */
public class HashMapListExample extends JFrame {

	private Map map = new HashMap();

	private JList list;

public HashMapListExample() {
		super("HashMapListExample");
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		map.put("a", "AAAAA");
		map.put("b", "BBBBB");
		map.put("c", "CCCCC");

		DefaultListModel model = new DefaultListModel();
		
		for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
			model.addElement(map.get(iter.next()));
		}

		list = new JList(model);

		getContentPane().add(list, BorderLayout.CENTER);

		pack();
		setVisible(true);
	}	public static void main(String[] args) {
		new HashMapListExample();
	}
}

Gruß Tom
 
vielen Dank !

Kannst du mir auch bitte sagen
wozu ich comparable, cloneable und serializable brauch ?
 
Zurück