Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Highlighting of selection in JList is an outline, not solid.  RSS feed

 
Ranch Hand
Posts: 122
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The selection in one of my JLists is being highlighted with an outline rather than a solid background. The correct bounds rectangle for the selection is outlined, not filled with the background color. What makes this so perplexing to me is the fact that another JList in another window is highlighting its selections properly, and I am using the same code for both JLists (with the obvious change in parameter values). Here are the two chunks of code. First, the defective code:



Next, the properly working code:


As you can see, the two code fragments are identical save for the parameter entry values and the differences inside the ListSelectionListeners. I zeroed in on the defective code's call to method SetUpNextEncounters:


Here is that method:


More debugging established that the failure is caused by line 11 in the bottom chunk of code. Since it alters bigJList, I'm guessing that it generates a ListSelectionEvent, which then calls the valueChanged Listener, which calls SetUpNextEncounters -- and away we go. However, I trapped this out with the Boolean userInput and a breakpoint revealed that this is not the case. That I am NOT getting a recursive loop from this.

I searched the Java docs for material on ListSelectionEvents, but could not figure out how it's being messed up. At this point, I'm stumped. I'm guessing that I don't understand Event handling to understand the problem.

Can anybody suggest a solution?
 
Rancher
Posts: 2958
20
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what your code is attempting to do, so I can only make some general comments:

1. Why would you use a visible row of "-1". The point of this method is to specify a reasonable number so the JList can determine its preferred size, so layout managers can use this information.

2. A ListSelectionListener is used to notify you when a selection has been made so you can do some processing. you should not be modifying the state of the JList within the listener.
 
Chris Crawford
Ranch Hand
Posts: 122
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Rob. The -1 parameter in setVisibleRowCount() is something I picked up in a demo that supposedly specifies some sort of default. Its one of those things that I got from somewhere that I have always used without a problem. I searched and found a number of sample programs that use it.

I have continued experimenting with the problem and come to the conclusion that modifying the JList in its own listener is just bad form. I had used a single method to handle a great many changes because it centralized everything and insured that all the interacting components were on the same page with the same data. I will break it down into specialized methods.

Thanks again!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!