JList

Ola galera…

tenho uma JList e quero fazer alguma coisa qdo a selecao dela mudar…
mas o evento estah disparando 2 vezes…

ai vai o codigo…

public class relatorio extends javax.swing.JFrame 
{
    public relatorio() 
{
        setSize(300,300);
        jList1 = new javax.swing.JList();

        getContentPane().setLayout(null);

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jList1.setBorder(new javax.swing.border.TitledBorder("Relatorios"));
        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Relatorio 1", "Relatorio 2", "Relatorio 3", "Relatorio 4" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
		jList1.addListSelectionListener(new ListSelectionListener()
		{
			public void valueChanged(ListSelectionEvent lse)
			{
				if (jList1.getSelectedValue().equals("Relatorio 1"))
				{
					JLabel lbl1 = new JLabel("1");
					lbl1.setBounds(200,200,50,20);
					getContentPane().add(lbl1);
					System.out.println("1");
				}
				if (jList1.getSelectedValue().equals("Relatorio 2"))
				{
					JLabel lbl2 = new JLabel("2");
					lbl2.setBounds(250,250,50,20);
					getContentPane().add(lbl2);
					System.out.println("2");
				}
			}
		});
        getContentPane().add(jList1);
        jList1.setBounds(40, 50, 72, 102);
    }

Rafael, uma boa dica é olhar o tutorial do Swing:

http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

Lá tem um código de um ListSelectionListener assim (olha como eu sou bonzinho, vou copiar pra vc):

public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting())
        return;

    JList theList = (JList)e.getSource();
    if (theList.isSelectionEmpty()) {
        picture.setIcon(null);
    } else {
        int index = theList.getSelectedIndex();
        ImageIcon newImage = new ImageIcon("images/" +
			(String)imageList.elementAt(index));
        picture.setIcon(newImage);
        picture.setPreferredSize(new Dimension(
                        newImage.getIconWidth(),
                        newImage.getIconHeight() ));
        picture.revalidate();
    }
}

A idéia é não fazer nada enquanto o model estiver sendo ajustado (ou seja, a seleção ainda não terminou).

Aquelão!!

valeu pela dica cara…

mas como uso esse evento no meu codigo???hehehe…

de acordo com a selecao da JList, tenho q habilitar ou desabilitar alguns campos…

valew pela ajuda…