import java.io.BufferedReader; import java.io.FileReader; import java.util.Map; import java.awt.*; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; public class Couleurs { public static void main(String[] args) { Map colorDict = new Hachage(); try (BufferedReader fs = new BufferedReader(new FileReader("rgb.txt"))) { String line; while ((line = fs.readLine()) != null) { String[] elements = line.trim().split("[\\s\t]+"); Color c = new Color(Integer.parseInt(elements[0]), Integer.parseInt(elements[1]), Integer.parseInt(elements[2])); String name = elements[3]; colorDict.put(name, c); } } catch (Exception e ) { System.out.println(e); } JFrame f = new JFrame(); f.setLayout(new GridLayout(1, 2)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(400, 250); String[] nameArray = new String[colorDict.size()]; colorDict.keySet().toArray(nameArray); JList list = new JList(nameArray); JScrollPane jpane = new JScrollPane(list); jpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); f.add(jpane); JPanel p = new JPanel(); f.add(p); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { p.setBackground(colorDict.get(list.getSelectedValue())); } }); f.setVisible(true); } }