• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

make a filterable jComboBox with selected columns

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading big data from text file by jComboBox using this code:


Text file have about 100 columns and I am reading necessary 2 column.

Here is readFile():


And I want to make a filterable jComboBox list using "Decorator" class:


I tried to use but in that case in jComboBox I am again getting contents of text file with all columns. In that case is not working. I w'd like to ask is there any way to show jComboBox1 with selected 2 column and by using "Decorator" class make filterable?
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm fairly sure there are freely available JComboBox implementations with filtering/auto completion available online that will do want you require, is there a specific reason you are writing your own?
Check out the following which I found with a quick search - there are probably loads more out there:
https://gist.github.com/cholland29/1216983
http://www.dzone.com/snippets/autocomplete-combobox-java
http://www.jroller.com/henribenoit/entry/filtered_combobox

BTW I haven't used any of these so can't recommend any of them.


As to your problem with displaying just two columns I would see if your code works correctly with a standard JComboBox first and if not fix that problem before trying to add the complexity of filtering.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code with displaying just 2 columns is working and for displayed with 2 column Combo list want to use ComboFilter class.
Before I couldn't find appropriate filter class for JComboBox so I used Decorator class.
I checked your suggested links. And I tried to use 3rd link for my JComboBox.
1. JComboBox reading text file and displaying just 2 column.
2. Tried to use this code to get filtered JComboBox

but output JComboBox list displays text file with all column.

I don't know how to implement filter class to JComboBox list with 2 columns.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JComboBox will display whatever you pass in to it as the list of displayable items so if you give it a list of strings it will display those strings, it knows nothing about columns. If you just want to display part of a String you have to pass in the part you want to display (as you have done using substring()) or alternatively you can create your own ListCellRenderer to handle displaying the appropriate subsection of each String in which case you can pass in the whole String.

The filter class you have chosen to use also requires a list of items to filter and display so again you have to pass in the appropriate list of substrings or if you are using a ListCellRenderer pass in the whole string and extend the ListCellRenderer to filter on only the parts of the String you want it to filter on (probably just the parts that are displayed).
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like Tony said, JComboBox doesn't support columns. But JTable does support both columns and filtering. Why don't you just use one of those?
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because my text file have around 100 columns and 1000 rows, so for quick search want to implement filter class.
So it means there is no way to use both of them?
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So it means there is no way to use both of them?


Not sure what you mean by both of them but it is certainly possible to have a filtered JComboBox that displays part of each row. You just need to make sure you are consistent with the data you pass into the JComboBox and the filter, See my last post.
 
Tai Yo
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I implemented filterable JComboBox with 2 column to Decorator class, but when I am reading text file with 1000 rows and typing some text to search on the JComboBox that moment combo list working very slowly and need to wait for some second to see the list of candidates.
If the rows is less (i.e. 20, 30, 50 rows) that moment JComboBox working normally and list of candidates appear quickly.
I couldn't understand why JComboBox with big data working slowly.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You really need to use a profiler to find out which section of code it taking the time and then once identified we may be able suggest a way of improving things.
If you haven't got a profiler fill the code with print statements outputting an identifier and the current time.
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldn't understand why JComboBox with big data working slowly. ---> JList has an performance issue together with event from SelectionModel, up to 999 Items is everything ok, without some performance issue

- replace DefaultComboBoxModel at runtime, or override MutableComboBoxModel with selection
 
reply
    Bookmark Topic Watch Topic
  • New Topic