...
ComponentListener componentListener = new ComponentListener() {
public void componentHidden(ComponentEvent e) {
checkScrollbar(e.getComponent(), false);
}
public void componentMoved(ComponentEvent e) {
}
public void componentResized(ComponentEvent e) {
}
public void componentShown(ComponentEvent e) {
checkScrollbar(e.getComponent(), true);
}
};
jScrollPane1.getVerticalScrollBar().addComponentListener(componentListener);
jScrollPane1.getHorizontalScrollBar().addComponentListener(componentListener);
...
private void checkScrollbar(Component component, boolean shown){
if(component instanceof JScrollBar){
JScrollBar scrollbar = (JScrollBar)component;
if(scrollbar.getOrientation() == JScrollBar.VERTICAL){
if(shown)
System.out.println("Vertical scrollbar shown");
else
System.out.println("Vertical scrollbar hidden");
}else{
if(shown)
System.out.println("Horizontal scrollbar shown");
else
System.out.println("Horizontal scrollbar hidden");
}
}
}
...