[英]How to find that jscrol knob hit the bottom corner?
當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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.