Java Swing Displaying Large Amounts of Data from ArrayLists

522 views Asked by At

I cannot provide code because this is an abstract problem that I am currently facing.

I am working on a program which allows a user to track players from games. The program essentially stores a players profile information in an ArrayList. One feature of my program that I would like is to let the user be able to browse through the entire ArrayList of players.

Let's say that I have an ArrayList of Player objects and the size is very large, say 1000. Is it possible in Java to allow the user to scroll through the ArrayList? I thought about creating 10 JLabels and each time a user clicked a button it would iterate through the ArrayList to the next 10 Player objects. But this does not seem practical.

Are there any Swing features I can utilize for this problem?

1

There are 1 answers

3
AudioBubble On BEST ANSWER

Try using a JTable, in which each table row contains the information for each player. You can extend the class AbstractTableModel to define the fields per player, and which player gets displayed on which table row.

I've written a Java app which uses JTables with more than 2000 rows, and about 15 to 20 columns, and had no performance issues. To limit the displayed rows, you can also use RowFilter, and you can customise the sorting using RowSorter.