TargetofGravity
TargetofGravity

Reputation: 343

Word wheel for JTable?

Word Wheel

For lack of better known terms I noted when going through some tutorials in Swing that JLists have a built in word wheel look up feature. I select anywhere in my list and start typing to navigate towards the items I want. Three questions to this:

  1. Is there a more appropriate term within the community for this style of searching?
  2. Looking through the JList API it wasn't apparent to me what resulted in this functionality. Any direction as to where to look would be appreciated, is it a function of what the constructor takes? I do not feel it is part of Component as JTables are components and do not seem to display this functionality; which leads me to....
  3. Can this functionality be applied as easily to JTables?

Upvotes: 0

Views: 89

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347314

Is there a more appropriate term within the community for this style of searching?

Autocomplete might be another term for what you're looking for.

Looking through the JList API it wasn't apparent to me what resulted in this functionality. Any direction as to where to look would be appreciated, is it a function of what the constructor takes? I do not feel it is part of Component as JTables are components and do not seem to display this functionality; which leads me to....

The functionality is provided by the JList#getNextMatch method, which is called by the UI delegate in response to a key event

Can this functionality be applied as easily to JTables?

Well, that's a subjective question and is based on your concept of easily

The problem is, it could actually interfere with the current default functionality of the JTable, which allows you to start editing a cell on a key event, so it might not be desirable.

JTable is a much more complex component, do you want to limit searching to a single column or include multiple columns? Do you want to use Object#toString (like JList) or provide a more flexible filtering mechanism?

You could take a look at How to use tables, Sorting and Filtering for a ready made alternative, but this might not meet your requirements.

Instead, I would provide a "search" field, which would allow the user to type their search query in. With a little work, you could make this search the table automatically and highlight the matches as the user types, but that's just me...

Upvotes: 3

Related Questions