java-MouseWheelListener块滚动
作者:互联网
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 );
}
}
标签:jeditorpane,block,java,scroll 来源: https://codeday.me/bug/20191201/2081762.html