JScrollPane中的JScrollPane [英] JScrollPane in JScrollPane
问题描述
我有一个JScrollPane
,其内容窗格中有一个JPanel
.在该JPanel
中添加较小的JPanel
,并且如预期的那样,如果添加过多的JPanel
,则会出现一个垂直滚动条.
I have a JScrollPane
, which has a JPanel
for its content pane. To that JPanel
I add smaller JPanel
s, and as expected, if I add too much JPanel
, a vertical scrollbar will appear.
问题是,我的小JPanel
对于JEditorPane
也包含一个JScrollPane
.我只想将鼠标滚轮仅用于外部滚动窗格,而不用于较小的滚动窗格.我已经将小滚动窗格的wheelScrollingEnabled()
设置为false
,但是如果我向任意方向滚动,并且鼠标越过JEditorPane
,则滚动将不再起作用.
The problem is, that my small JPanel
s contains a JScrollPane
too for a JEditorPane
. I'd like to use the mouse wheel only for the outer scrollpane, not for the smaller scrollpane. I already set wheelScrollingEnabled()
to false
for the small scrollpane, but if I scroll in any direction, and the mouse gets over the JEditorPane
, the scrolling doesn't work anymore.
有什么建议吗?
推荐答案
您可以尝试将wheel事件从内部滚动窗格转发到其父级.
You may try to forward the wheel events from the inner scroll pane to its parent.
innerScrollPane.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
innerScrollPane.getParent().dispatchEvent(e);
}
});
这篇关于JScrollPane中的JScrollPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!