This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JList selection questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList selection questions" Watch "JList selection questions" New topic

JList selection questions

Tod Sterben

Joined: May 05, 2003
Posts: 7
I want to open a new frame when a selection is made from a JList and send the value in the selected cell in the JList to the new frame.
How do I set up a listener to do that without the code (listed below) producing two rows and also two new windows, as shown below

0 [Cliff House Restaurant, 1090 Point Lobos Avenue, San Francisco - Outer Sunset, , California Cuisine]
0 [Cliff House Restaurant, 1090 Point Lobos Avenue, San Francisco - Outer Sunset, , California Cuisine]

public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
if (theList.isSelectionEmpty()) {
} else {
if (isDone == false) {
int index = theList.getSelectedIndex();
System.out.println(index + " " + theList.getSelectedValue());
Object theValue = theList.getSelectedValue();
String pString = theValue.toString();
Out2SecondGui newgoo = new Out2SecondGui((String) "two");
isDone = true;
[ May 07, 2003: Message edited by: Tod Sterben ]
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Don't know why you're getting two calls... the e.getValueIsAdjusting() call should filter out the "deselected" event... perhaps you are registering two event listeners on your list?

This code is working out fine for me...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
wood burning stoves
subject: JList selection questions
Similar Threads
JRadioButtonList error
JList model elements pre exist, updating of vector does not change model
MultipleSelect JComboBox
Where to take SCBCD in the Bay Area?
problem selecting JList item