我在三个不同的jscrollpane上有三个不同的jtable - 一个在另一个旁边.
我成功地编写了一些代码,当我滚动鼠标滚轮时,它们会一起滚动.
我继承了JScrollpane并覆盖了它的processMouseWheelEvent方法,如下所示:
public void processMouseWheelEvent(MouseWheelEvent e) {
...
if (e.getSource() == this) {
for (BTSJScrollPane other : effected) {
other.processMouseWheelEvent(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经使用了限制页面向下翻页
final InputMap inputMap =
comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke("PAGE_DOWN"), EMPTY);
inputMap.put(KeyStroke.getKeyStroke("PAGE_UP"), EMPTY);
comp.getActionMap().put(EMPTY, emptyAction);
Run Code Online (Sandbox Code Playgroud)
但是,
我现在唯一的问题是,当用户上下咔哒一声时,他们不会一起走,而是会不知不觉地滚动.
有什么建议 ?
到目前为止,我在滚动条中写了类似的内容
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
@Override public boolean dispatchKeyEvent(KeyEvent e) {
if (thisIsThesourceTable) {
if (e.getKeyCode() == 38 || e.getKeyCode() == 40) {
}
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
但是:
1.有更好的方法吗?
也许我应该在actionMap中以某种方式做到这一点?
3.如何将键上/下事件传递给另一个滚动窗格?
4.我可以知道我是否接近滚动窗格中查看部分的末尾?它是否需要