• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JList selection questions

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()) {
return;
}
if (theList.isSelectionEmpty()) {
return;
} 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");
newgoo.drawMain();
isDone = true;
}
}
}
[ May 07, 2003: Message edited by: Tod Sterben ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic