jlist

Discussion in 'Java' started by dario.8282@hotmail.it, Jan 25, 2008.

  1. Guest

    i have a jlist; i put in a vector of string

    Vector v_righe = new Vector();
    JList list_righe = new JList(v_righe);

    i select an element of the jlist with the mouse
    i would like to deselect the element push a button...

    i call
    list_righe.clearSelection();

    ....that cause the exception:

    Exception in thread "AWT-EventQueue-1"
    java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.Vector.get(Vector.java:696)

    i have tried to do these controls...

    if(v_righe.size()>0){
    if(!list_righe.isSelectionEmpty())
    list_righe.clearSelection();
    }

    but it's the same...
    what's the problem?
    thank's!
    , Jan 25, 2008
    #1
    1. Advertising

  2. Evans Guest

    I would like to help, but its very hard to understand what you want to
    achieve.

    My advice would be to post a sample code and clearly tell us what
    you're looking to achieve.


    wrote:
    > i have a jlist; i put in a vector of string
    >
    > Vector v_righe = new Vector();
    > JList list_righe = new JList(v_righe);
    >
    > i select an element of the jlist with the mouse
    > i would like to deselect the element push a button...
    >
    > i call
    > list_righe.clearSelection();
    >
    > ...that cause the exception:
    >
    > Exception in thread "AWT-EventQueue-1"
    > java.lang.ArrayIndexOutOfBoundsException: -1
    > at java.util.Vector.get(Vector.java:696)
    >
    > i have tried to do these controls...
    >
    > if(v_righe.size()>0){
    > if(!list_righe.isSelectionEmpty())
    > list_righe.clearSelection();
    > }
    >
    > but it's the same...
    > what's the problem?
    > thank's!
    Evans, Jan 25, 2008
    #2
    1. Advertising

  3. wrote:
    > i have a jlist; i put in a vector of string
    >
    > Vector v_righe = new Vector();
    > JList list_righe = new JList(v_righe);
    >
    > i select an element of the jlist with the mouse
    > i would like to deselect the element push a button...
    >
    > i call
    > list_righe.clearSelection();
    >
    > ...that cause the exception:
    >
    > Exception in thread "AWT-EventQueue-1"
    > java.lang.ArrayIndexOutOfBoundsException: -1
    > at java.util.Vector.get(Vector.java:696)
    >
    > i have tried to do these controls...
    >
    > if(v_righe.size()>0){
    > if(!list_righe.isSelectionEmpty())
    > list_righe.clearSelection();
    > }
    >
    > but it's the same...
    > what's the problem?
    > thank's!


    It works just fine for me.

    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;

    public class test2 {
    public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector v = new Vector();
    v.add("One");
    v.add("Two");
    v.add("Three");
    final JList l = new JList(v);
    f.add(l,BorderLayout.CENTER);
    JButton b = new JButton("Clear Selection");
    b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    l.clearSelection();
    }
    });
    f.add(b,BorderLayout.SOUTH);
    f.pack();
    f.setVisible(true);
    }
    });
    }
    }

    --

    Knute Johnson
    email s/nospam/knute/

    --
    Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
    ------->>>>>>http://www.NewsDemon.com<<<<<<------
    Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
    Knute Johnson, Jan 25, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Passero

    JList question

    Passero, Jun 28, 2003, in forum: Java
    Replies:
    1
    Views:
    1,093
    Stephan Friedrichs
    Jun 28, 2003
  2. Sam
    Replies:
    0
    Views:
    878
  3. Tom

    JList problem.

    Tom, Jul 30, 2003, in forum: Java
    Replies:
    1
    Views:
    688
  4. Tom

    JList Problems

    Tom, Jul 30, 2003, in forum: Java
    Replies:
    1
    Views:
    431
    Dave Roberts
    Jul 30, 2003
  5. Jared
    Replies:
    0
    Views:
    690
    Jared
    Jul 31, 2003
Loading...

Share This Page