I have solved this today! I used a static variable called pageNum which is my page variable. Now the method that takes care of the JComboBox event looks like this
But anyway, you were right. The error had to do with pageNum that did'nt decrement properly after a JComboBox event. I have managed to paginate both backward and forward now between pages of 10 records. I am pleased with the result
I hate to say this, but this whole approach is over-complicated. Maintaining a GUI Table Model based on a slice of a SQL query is only a moderately-difficult problem. Its essence it this:
1. You have two maintenance values: the current row number ("X") and the number of rows to pull into the table ("N").
2. When you wish to initially fill or page the table, you discard the model's current row collection, do the query and tell it to return starting with row "X" and returning "N" nows. Read those rows and build Model row objects which are then added to the table. Once the table model is updated, you can refresh its display (in desktop UI's that's "invalidate" the UI element(s) in question).
3. To page forwards, increment "X" by adding "N" to it to get the new "X", then repeat step 2. To page backwards, subtract "N" from "X", and if the result is less than 1, set "X" to 1, since there are no zero or negative rows.
Other considerations: the last page of the SQL results may contain less than "N" rows. That's fine, but you get extra points for setting an indicator that "X" cannot be incremented further. That may include disabling the "forward" button. Likewise, when "X" is less than "N", disable the page-back button.
And remember, each time you execute Step 2, you are doing a brand new query. If any of the underlying rows of the query have been modified or if rows have been inserted and/or deleted, it can affect the repeatability of the results being displayed. Therefore you should only attempt to page data sets that you know will not be altered while they are being viewed.
Got idle CPU cycles? Join the war on COVID-19 by donating them to find the coronavirus' weak spots. folding@home Runs in the background. https://foldingathome.org
Stop it! You're embarassing me! And you are embarrassing this tiny ad!