protected JScrollPane embeddInScrollPane(JTable table) { JScrollPane pane = new JScrollPane(table); pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar()); return pane; }
/** * Wires a {@link JCheckBox} to the adjustment synchronizer, in such a way that: * * <ol> * <li>state changes in the checkbox control whether the adjustable participates in synchronized * adjustment * <li>state changes in this {@link AdjustmentSynchronizer} are reflected in the {@link * JCheckBox} * </ol> * * @param view the checkbox to control whether an adjustable participates in synchronized * adjustment * @param adjustable the adjustable * @throws IllegalArgumentException if view is null * @throws IllegalArgumentException if adjustable is null */ public void adapt(final JCheckBox view, final Adjustable adjustable) { CheckParameterUtil.ensureParameterNotNull(adjustable, "adjustable"); CheckParameterUtil.ensureParameterNotNull(view, "view"); if (!synchronizedAdjustables.contains(adjustable)) { participateInSynchronizedScrolling(adjustable); } // register an item lister with the check box // view.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { switch (e.getStateChange()) { case ItemEvent.SELECTED: if (!isParticipatingInSynchronizedScrolling(adjustable)) { setParticipatingInSynchronizedScrolling(adjustable, true); } break; case ItemEvent.DESELECTED: if (isParticipatingInSynchronizedScrolling(adjustable)) { setParticipatingInSynchronizedScrolling(adjustable, false); } break; } } }); observable.addObserver( new Observer() { @Override public void update(Observable o, Object arg) { boolean sync = isParticipatingInSynchronizedScrolling(adjustable); if (view.isSelected() != sync) { view.setSelected(sync); } } }); setParticipatingInSynchronizedScrolling(adjustable, true); view.setSelected(true); }