Your explanation of your situation is kinda vague. Are your lists in the same
scroll pane or do
they have their own separate scroll pane?
Nevertheless, you might want to have a look at this:
package org.blahblah;
import javax.swing.*;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.util.Vector;
public class ClickOnTextField {
public static void main(String[] args) {
JFrame frame = new JFrame();
Vector<String> leftData = createData("left");
JList leftList = new JList(leftData);
final JScrollPane leftScroll = new JScrollPane(leftList);
Vector<String> rightData = createData("right");
JList rightList = new JList(rightData);
final JScrollPane rightScroll = new JScrollPane(rightList);
JPanel panel = new JPanel();
BoxLayout boxLayout = new BoxLayout(panel,
BoxLayout.X_AXIS);
panel.setLayout(boxLayout);
panel.add(leftScroll);
panel.add(Box.createHorizontalStrut(5));
panel.add(rightScroll);
leftScroll.getViewport().
addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent e) {
rightScroll.getViewport().
setViewPosition(leftScroll.getViewport().
getViewPosition());
}
});
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
public static Vector<String> createData(String side) {
Vector<String> data = new Vector<String>();
for (int i = 0; i < 50; i++) {
data.add(i + side);
}
return data;
}
}