Reputation: 9103
I have a JTable that has a constantly increasing number of rows (potentially an infinite number). A solution to avoid high memory usage is "caching" the content to a file and retrieving pages/chunks of data from this file, based on the current scrollbar cursor position. Another "extra" problem is filtering down this data based on column values. As I assume it is a known problem and to avoid reinventing the wheel, I am wondering if there are any ready-made widgets/libraries for this purpose. I couldn't find anything just googling.
Upvotes: 2
Views: 1691
Reputation: 13509
Swing bits here has a column filter :
http://code.google.com/p/oxbow/
Upvotes: 0
Reputation: 21748
JTable
only reads data from its model when it needs to display that data. Invisible parts (normally when the table is placed into scroll pane) can be very huge without any impact on performance, as long as your model can manage this.
I suggest to implement the model on the top of relational database selecting the required columns with SQL through JDBC. In the simplest case, any row can be loaded as
select field1, field2, field2 .. field2 from myTable
offset row_number limit 1;
Such statement is also an ideal candidate to be a prepared statement. The only thing that may not work well is sorting as any sorter needs to see all values in a column to decide about the order. However you can use the database engine sorting instead:
select field1, field2, field2 .. field2 from myTable
order by field1 desc
offset row_number limit 1;
If there is an index on the field1
, the database engine can use that index without actually sorting the column.
If performance is not sufficient, it is possible to experiment with more complex model that gets several rows at once and uses some caching. However a descent database can pull a lot and this may not be necessary.
Upvotes: 2
Reputation:
an example of such table is here:
http://www.java2s.com/Code/Java/Swing-JFC/PagingorpagableJTableTableModelforlargedataset.htm
yet, Please see the first option in the accepted answer in the following regarding the "extra problem" that you have mentioned:
Very big JTable, RowFilter and extra load
filtering requires scanning the whole data so even if you don't use a relational database like the answer there suggests, then consider using one or any other non sql database that provides fast search and filtering.
Upvotes: 1