简体   繁体   中英

How to find that jscrol knob hit the bottom corner?

I want to make an event when the jscroll knob hit the bottom corner in VerticalScrollBar . How to do it?

import javax.swing.*;
import java.awt.*;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;

public class JScrollBarTest {
    public static void main(String[] args) {
        JFrame fr=new JFrame();

        JLabel l=new JLabel("test");
        l.setPreferredSize(new Dimension(500, 500));
        JScrollPane scroll=new JScrollPane(l);
        fr.add(scroll);
        scroll.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
            @Override
            public void adjustmentValueChanged(AdjustmentEvent e) {
                JScrollBar sc=scroll.getVerticalScrollBar();
                System.out.println(sc.getVisibleAmount());
                System.out.println(sc.getMaximum());
                System.out.println(sc.getValue());
                System.out.println("------");
                if (sc.getVisibleAmount()+sc.getValue()==sc.getMaximum()) {
                    System.out.println("Bottom event");
                }
            }
        });

        fr.setSize(100, 100);
        fr.setLocationRelativeTo(null);
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fr.setVisible(true);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM