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?
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.
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.
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).
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.
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.
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.