Problem with focus on JList  
Author Message
Daniel Moritz





PostPosted: 2003-7-16 22:28:00 Top

java-programmer, Problem with focus on JList Hi!
I got 2 JLists . I doubleclick an item to display it's details.
This works fine so far, but:
When I select an item in JList1 and in JList2 the Mouselistener doesn't
know from which JList he should get the item.
So I had the idea that when you select an item in JList1 JList2 should
loose all selections.
But I just don't get it done.
any ideas?

 
Daniel Moritz





PostPosted: 2003-7-17 3:17:00 Top

java-programmer >> Problem with focus on JList Thomas Weidenfeller wrote:
> Daniel Moritz <email***@***.com> writes:
>
>>When I select an item in JList1 and in JList2 the Mouselistener doesn't
>>know from which JList he should get the item.
>
>
> Are you using the same listener for two different components? This is,
> aehm, uncool. If you implement separate mouse listeners, you know
> from which source the event comes. I am also surprised that you go for
> a mouse listener and not for action event handlers.
>
How would I implement two different MouseListeners?
My code is sth like this:
JList dataList = new JList();
JList charList = new JList();
dataList.addMouseListener(this);
charList.addMouseListener(this);
I'm using a MouseEventListener because I want to double-Click the item
to show its details (it opens another window showing some text).
This code is like this:
public void mouseClicked(MouseEvent e) {
if (dataList.getSelectedIndex() >= 0 && (e.getClickCount() == 2)){
mymethod(); }
>
>>So I had the idea that when you select an item in JList1 JList2 should
>>loose all selections.
>
>
> I don't see how this should all fit together (show us code!). You are
> talking about focus in the subject line, now you are talking about
> selection. Two completely different things. But here we go:
>
> To clean a list selection, something like
>
> theJList.getSelectionModel().clearSelection();
>
> should do.
>
> If you want to stick with the one handler for multiple components, you
> could use getSource() on the event to find out.
>
>
> /Thomas