* fixed some scrollpane synchronization issues

This commit is contained in:
Reinhard Pointner 2009-07-25 13:17:13 +00:00
parent 134eba228b
commit afbc49369a
1 changed files with 26 additions and 12 deletions

View File

@ -8,9 +8,8 @@ import java.awt.event.ActionListener;
import javax.swing.BoundedRangeModel; import javax.swing.BoundedRangeModel;
import javax.swing.Timer; import javax.swing.Timer;
import javax.swing.event.ListDataEvent;
import ca.odell.glazedlists.event.ListEvent; import javax.swing.event.ListDataListener;
import ca.odell.glazedlists.event.ListEventListener;
class ScrollPaneSynchronizer { class ScrollPaneSynchronizer {
@ -26,23 +25,34 @@ class ScrollPaneSynchronizer {
BoundedRangeModel verticalScrollBarModel = components[0].getListScrollPane().getVerticalScrollBar().getModel(); BoundedRangeModel verticalScrollBarModel = components[0].getListScrollPane().getVerticalScrollBar().getModel();
// recalculate common size on change // recalculate common size on change
ListEventListener<Object> resizeListener = new ListEventListener<Object>() { ListDataListener resizeListener = new ListDataListener() {
private final Timer timer = new Timer(50, new ActionListener() { private final Timer timer = new Timer(50, new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
syncSize(); updatePreferredSize();
// run only once // fire only once
timer.stop(); timer.stop();
} }
}); });
@Override @Override
public void listChanged(ListEvent<Object> evt) { public void intervalAdded(ListDataEvent e) {
// sync size when there are no more events coming in timer.restart();
}
@Override
public void intervalRemoved(ListDataEvent e) {
timer.restart();
}
@Override
public void contentsChanged(ListDataEvent e) {
timer.restart(); timer.restart();
} }
}; };
@ -52,12 +62,15 @@ class ScrollPaneSynchronizer {
component.getListScrollPane().getHorizontalScrollBar().setModel(horizontalScrollBarModel); component.getListScrollPane().getHorizontalScrollBar().setModel(horizontalScrollBarModel);
component.getListScrollPane().getVerticalScrollBar().setModel(verticalScrollBarModel); component.getListScrollPane().getVerticalScrollBar().setModel(verticalScrollBarModel);
component.getModel().addListEventListener(resizeListener); component.getListComponent().getModel().addListDataListener(resizeListener);
} }
// initial sync of component sizes
updatePreferredSize();
} }
public void syncSize() { public void updatePreferredSize() {
Dimension max = new Dimension(); Dimension max = new Dimension();
for (RenameList component : components) { for (RenameList component : components) {
@ -79,6 +92,7 @@ class ScrollPaneSynchronizer {
component.getListComponent().setPreferredSize(max); component.getListComponent().setPreferredSize(max);
// update scrollbars // update scrollbars
component.getListComponent().revalidate();
component.getListScrollPane().revalidate(); component.getListScrollPane().revalidate();
} }
} }