• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JList selection acting strange

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have JList that is loaded with Object<Domain> has its ListCellRenderer and mouseListener, here is the code:

MyListCellRenderer:



JList:



Domain class:


That is the setup. What am I doing is getting data from a data base and loading it to a JList. The next step is the one when I click on a row in the list I want another Jlist to load corresponding filed from a data base.

Everything is working fine. I get the right values at my terminal but when I try to load the values to the other JList the first one that triggered the job is acting strange.What I mean by acting strange is the following. The list that has a mouseListener attached to it has 9 Domain elements in it(it only shows Domain.getName()). When I make a selection(one click) I get the right data in the second Jlist loaded, but the selection marker moves in the first one on its own. It moves one spot down, and it happens 9 times, and I don't have a clue why is that happening.

This is the listener code:



Does anyone have a clue to whats going on here? Thanks
 
Ivan Ristic
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone help out?
i am bit confused about this whole thing. if i am getting selection from one list and based on that selection i am loading data into another Jlist, why is that when i click on the second Jlist selection is connected with the first list, also the first list selection is jumping one filed down...can anyone help me out, i am really stuck here.thanks
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PatienceIsAVirtue. People on this site volunteer their time for free to help you out. Expecting a reply within 40 minutes of the post is unfair.

Firstly, why do you use a MouseListener? You should be using an ActionListener. Secondly, decouple the problem from database calls. Create a SSCCE which shows this problem and it is also easier to help that way.
 
Ivan Ristic
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry sir, you are completely right.
Would like to say upfront that i am grateful for any help and wisdom someone shares.

My thinking for using the MouseListener is that i wanted actions based upon number of mouse clicks, one click send some values to other Jlists and two clicks something completely different. MouseListener sounded like a logic way.

I decoupled the problem from database calls. Here is a simple example that anyone can run and see exactly what my problem is...



When someone clicks load button first Jlist gets populated, my desire is that when a row in that Jlist is selected i pass some data to the other Jlist.... as you can see selection in the first list switches and when something is clicked in the second Jlist it affects selection in the first Jlist . What am i doing fundamentally wrong here.
thanks

 
Ivan Ristic
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have figured it out.

had to implement different selection model for the listRN and listPL. now everything is working fine

thanks for help
 
Marshal
Posts: 80212
423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done sorting it out Please show us what the solution was.
 
Ivan Ristic
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both my list: listRN and listPL were implementing the same DefaultListSelectionModel.



now we add this change and everything is working just fine:



listPL and listRN should not have the same ListSelectionModel, when you select an item in the first list it's added to the second list and the selected item within it is changed so also the selected item of the first list is changed because they have the same ListSelectionModel.
 
Campbell Ritchie
Marshal
Posts: 80212
423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic