Reputation: 771
I want to use a JList to display records retrieved from a database.
Because a database table may have a large number of records, paging is better than scroll bar, which means to put 4 buttons "First", "Prev", "Next", "Last" below the list.
To implement paging, I must know how many records I should request from the database for one page. When the window is resized by the user, I also need to recalculate the "page size" and access the database again.
The question is, how can I know how many rows can be completely displayed in the JList control? (suppose a row to be displayed in the JList is just a simple text line. Rows are identical in height).
Thank you!
Upvotes: 1
Views: 189
Reputation: 285430
You can display as many rows as needed in the JList. Simply
.setVisibleRowCount(...)
.setPrototypeCellValue(...)
to a value that shows an adequate widthRegarding:
Because a database table may have a large number of records, paging is better than scroll bar
But that is not how JLists have been built to work, and so you will be fighting against the GUI library design if you try to implement this in the GUI directly. Perhaps better to implement a paging construct on the database data acquisition side of things.
Upvotes: 1