• 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

problems index after adding element to a Jlist

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I can finally add a new element to a Jlist.
Everything works out fine when I add a new element without selecting something first.
When I have selected something from the Jlist and try to add a new item I get the following errors on the outputscreen :
Connection established successfully!
rowssize = 7
newIndex Jlist = 6
rowssize = 8
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: -1 < 0
at java.util.Vector.elementAt(Vector.java:427)
at veld.VeldGUI.veldenListSelected1(VeldGUI.java:235)
at veld.VeldGUI.access$300
Here is the code for the actionHandler when I add an new element,FYI I work with vectors and not the DefaultListModel.

valueList.addElement(v.getName());
veldenList.setListData(valueList);
veldenList.repaint();
// Here I put the index of the Jlist to the added element
int newIndex = (rows.size()-1);
veldenList.setSelectedIndex(newIndex);
System.out.println ("newIndex Jlist = " +
newIndex);
Here is my ListSelectionListener when an item is selected :
private void veldenListSelected1(javax.swing.event.ListSelectionEvent evt) {
tfVeldNaam.setText((String)veldenList.getSelectedValue());
cbType.setSelectedIndex(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getType());
tfLengte.setText(new Integer(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getLengte()).toString());
veldDetails.setText(((Veld)rows.elementAt(veldenList.getSelectedIndex())).getOmschrijving());

Thanks
Kristof
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic