i.e. the code of your ListSelectionListener.valueCanged()-method....
> Could you post some lines of your source along with your question? This
> would be helpfull...
Good idea. Some actual lines from the OP's breaking code
would get us closer to an answer.
Unfortunately, if code is breaking, it is not always obvious
which bit is broken, so the OP often posts lines of code they
*suspect* of causing the problem, when in fact it is elsewhere.
For that reason (and others) I suggest, not code snippets,
but an SSCCE[1], which the OP should be able to do in less
than 30[2] lines of code.
[1] <http://www.physci.org/codes/sscce.jsp>
[2] I'd have said 20, but give allowances for a first attempt.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"Takes her over the breakers, to where the water is calm.."
Paul Kelly 'Deeper Water'
bwilde@gmail.com - 05 Sep 2005 03:01 GMT
Well, the code is not actually breaking. Everything compiles just
fine. So, hopefully, snippets will add some insight...
In my main class, I have:
DefaultListModel model = new DefaultListModel();
JList fileList = new JList(model);
fileList.setSelectedIndex(0);
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fileList.setLayoutOrientation(JList.VERTICAL);
fileList.addListSelectionListener(new FileListListener());
I then add elements to my list with code similar to this:
for(int i = 0; i < 6; i++)
model.add(i,"ListElement");
And my listener class looks like this:
protected class FileListListener implements ListSelectionListener
{
public void valueChanged(ListSelectionEvent e)
{
if(e.getValueIsAdjusting())
return;
System.out.println("Index: " + fileList.getSelectedIndex());
}
}
So, everything builds just fine and the GUI looks great. Every time I
click on a list element, it prints Index: -1. This tells me that the
listener is set up fine, but that something is not in place so my JList
knows what is selected.
Does this help?
Thanks,
Ben
Andrew Thompson - 05 Sep 2005 03:10 GMT
> Well, the code is not actually breaking.
Yes it is.
>..Everything compiles just fine.
Yes, but my definition of 'break' is.. written in the
document to which I linked. Did you read it?

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"I talk of freedom, you talk of the flag. I talk of revolution, you'd much
rather brag.."
Live 'White Discussion'
Michael Dunn - 05 Sep 2005 03:20 GMT
you will get the described behaviour if you have this line twice
JList fileList = new JList(model);
1) as a class member
2) inside the constructor
remove (2) and it should be OK
bwilde@gmail.com - 05 Sep 2005 03:23 GMT
Ah beautiful. Thank you very much... that was exactly my problem.
Thanks again!
Thomas Hawtin - 05 Sep 2005 15:28 GMT
> Ah beautiful. Thank you very much... that was exactly my problem.
> Thanks again!
Pity it was only indirectly implied by the code eventually given.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/