aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JList, modifying keyboard search. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList, modifying keyboard search." Watch "JList, modifying keyboard search." New topic
Author

JList, modifying keyboard search.

Jiri Nejedly
Ranch Hand

Joined: Oct 22, 2002
Posts: 81
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

Joined: Jun 19, 2012
Posts: 155
- 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

Joined: May 03, 2008
Posts: 4638
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Jiri Nejedly
Ranch Hand

Joined: Oct 22, 2002
Posts: 81
I finally googled a solution. It is based on modifying keyPressHandler method. Full code:

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4638
    
    5

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList, modifying keyboard search.