Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > jlist

Reply
Thread Tools

jlist

 
 
dario.8282@hotmail.it
Guest
Posts: n/a
 
      01-25-2008
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!
 
Reply With Quote
 
 
 
 
Evans
Guest
Posts: n/a
 
      01-25-2008
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.


(E-Mail Removed) 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!

 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      01-25-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting the previously selected index for JList Jared Java 0 07-31-2003 07:39 AM
JList Problems Tom Java 1 07-30-2003 03:15 PM
JList problem. Tom Java 1 07-30-2003 12:53 PM
JList question - how to fire a change event when nothing has changed? Sam Java 0 07-17-2003 10:40 PM
JList question Passero Java 1 06-28-2003 12:17 PM



Advertisments