Skip to main content

Problem with JList(ListSelectionListener())

2 replies [Last post]
Joined: 2010-03-25

Hello boys and girl.

I have create i JList in my application and i want that when i click on the element in the JList, a String Variable must be create with the name of the element.

I have realized hit but when i click on the element this variable is create 2 times.

The code example is:

<br />
JPanel stuffPanel = new JPanel();<br />
        String[] scelte = {"una", "due", "tre", "quattro"};<br />
        final JList lista = new JList(scelte);</p>
<p>        lista.addListSelectionListener(new ListSelectionListener(){<br />
        	public void valueChanged(ListSelectionEvent e){<br />
        		String valore=(String) lista.getSelectedValue();<br />
        		System.out.println(valore);<br />
        		try{<br />
        	        createSwingInternalFrame( desktopPane, "My CICCIO", 10, 150 );<br />
        	}catch(Exception a){}<br />
        	}<br />
        }<br />
        );<br />

Can you helo me??

Excuse me for my english


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-01-02
Joined: 2007-04-17

Check the tutorial as suggested and in this specific case ListSelectionEvent#getValueIsAdjusting().