我想在 jscroll 旋钮击中VerticalScrollBar
的底角时做一个事件。怎么办?
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);
}
}