gpt4 book ai didi

java - MouseWheelListener block 滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:58:41 24 4
gpt4 key购买 nike

    JEditorPane.addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
}
});

当我添加这些行时 - 在 JEditorPane 中滚动停止工作。如何治愈?

最佳答案

您应该发布更多代码以获得更好的帮助。然而,这个简单的演示对我来说效果很好(即在将 MouseWheelListener 添加到 JScrollPane 后滚动仍然有效)。

import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

public class Frame
{
public static void main( String[] args )
{
JFrame frame = new JFrame( );
JEditorPane pane = new JEditorPane( );

String t = "";
for ( int i = 0 ; i < 10000 ; i++ ) t += "t";

pane.setText( t );

JScrollPane scroll = new JScrollPane( pane );

scroll.addMouseWheelListener( new MouseWheelListener( )
{
@Override
public void mouseWheelMoved( MouseWheelEvent e )
{
System.out.println( "Scroll" );
}
});

frame.add( scroll );
frame.setSize( 400, 400 );
frame.setVisible( true );
}
}

关于java - MouseWheelListener block 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9855941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com