• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList Autosearch with Custom Renderer

 
Bruce Saunders
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JList that I need to implement that requires a custom renderer, but when it is used the JList "loses" its ability to do selections when the user types what they want to select. The reason for the renderer is that I need to store HashMaps in the JList and need to display a "user-friendly" name in the list. If there were only a small number of items to display, I wouldn't worry too much about this, but there will be around 200 - 300 items in the list and giving the user the ability to "type and find" is desired. So far everything else for the JList is working as expected except this.


Thanks,
Bruce Saunders
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's often helpful to provide the code that you are having a problem with.
 
Bruce Saunders
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, here are the various class files --

HashFill - is the object that is in the JList


HashFillRenderer -- the JList renderer


HashFillModel -- the JList model


And here is where I setup the JList --
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works OK for me - win98SE, java 1.4.0_01

if you're using java 1.5, this'll be just another 'broken' feature
 
Bruce Saunders
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting, I'm using 1.4.2_08 on WinXP. I'll try it with someother variations and see what happens.


Thanks!!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to be all the same on 1.5.0_03 and 1.4.2_08 (home pc's)

perhaps the problem is that you've set a preferredSize for the JList
instead of for the scrollpane - so the selections (if outside the view)
do not show.
 
Bruce Saunders
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael! That was part of my problem (sometimes I can't see the forest for the trees!!) I also found out that in my HashFill class, the toString() method wasn't always working properly. I removed the name variable and made the toString() method return get("name") and it started working just fine.

Thanks for pointing out the error of my ways! <g>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!