Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JList, modifying keyboard search.

 
Jiri Nejedly
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have simple JList with ordered list of Strings (let's say song names for example). I found out that quick keyboard typing automatically searches prticular line. Am I able to modify that behavior ? Let's say I need to add on the beginning of each line some visible metadata ([mp3], [wav], [mpa],...) which makes the searching stop working. I would like to start searching at first char after ']' (sorting will not change). Is it possible ? Thanks.
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- probably will be problem for another --->
What are you trying to achieve, I'm fail to understand what you are asking exactly, not clear something from your question, nor for JComponents and its basic properties or methods implemented in API

- </Slovak language, short version ---> ani prd tomu nerozumiem/>

- for better help sooner post an SSCCE, short, runnable, compilable, just about a.m. issue, e.g. JFrame with JList, with hardcoded value (let's say song names for example) for DefaultListModel
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand what you're trying to do. My guess is that you would need to override JList#getNextMatch(...) which you can find at or around lines 1437 to 1474 in JList.java.

I haven't investigated where else that method is used, so there may be some unwanted side effects to be taken care of.
 
Jiri Nejedly
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I finally googled a solution. It is based on modifying keyPressHandler method. Full code:

 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may be missing something, but I don't see any way that posted code snippet would ignore prefixed metadata like [mp3], [wav], [mpa]. I would use a regex in a getNextMatch override to ignore any prefix enclosed in square brackets. This requires just one method and two lines added to the JList code.

(Edited to shorten long lines)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic