Skip to content

Commit

Permalink
load additional pages if user scrolled to the bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed May 30, 2024
1 parent 99647f4 commit 5542c9f
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JScrollBar;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -753,11 +754,13 @@ public PdfImageScrollingPanel(String fileName, byte[] content, DocumentPreviewSa
// Now you have the index of the JLabel currently displayed
// You can access it like this:
if (labelIndex != -1 && labelIndex < components.length) {
//JLabel currentLabel = (JLabel) components[labelIndex];
// Do whatever you need with the currentLabel

// begin rendering additional pages once the user scrolls to the 2nd last page
if (((labelIndex + 1) == renderedPages || (labelIndex + 1) == renderedPages - 1) && renderedPages < totalPages && !rendering) {

// begin rendering additional pages once the user scrolls to the bottom
JScrollBar scrollBar = (JScrollBar) e.getAdjustable();
int max = scrollBar.getMaximum();
int extent = scrollBar.getModel().getExtent();
int value = scrollBar.getValue();
if (value + extent >= max) {
this.renderContent(labelIndex, renderedPages, renderedPages + MAX_RENDER_PAGES, zoomFactor);
}

Expand Down

0 comments on commit 5542c9f

Please sign in to comment.