我在JScrollpanel中设置的内容是一个流式布局的Panel。在JScrollpanel上添加MouseListener
和MouseMoutionListener。实现拖动内容Panel,来滚动。
但是内容拖动成功了,却没有刷新 新的部分。JScrollPanel的滚动条也没有滚动。请问这是为什么?
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getSource().equals(leftTopJSL)){
if(letopy==0){
letopy=e.getY();//记录的上次临时变量
}else{
int temp=e.getY()-letopy;
Point p=leftTopJSL.getViewport().getLocation();
letopy=e.getY();
p.setLocation(0, temp+p.getY());
leftTopJSL.getViewport().setLocation(p);//为JScrollPanel从新设置滚动位置
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getSource().equals(leftTopJSL)){
letopy=0;//鼠标松开时,位置归零
}
}
http://blog.csdn.net/leongod/article/details/5967838
JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
Creates a JScrollPane that displays the view component in a viewport whose view position can be controlled with a pair of scrollbars.
VERTICAL_SCROLLBAR_NEVER,HORIZONTAL_SCROLLBAR_AS_NEEDED
或者
voidsetHorizontalScrollBarPolicy(int policy)
Determines when the horizontal scrollbar appears in the scrollpane.
void setVerticalScrollBarPolicy(int policy)
Determines when the vertical scrollbar appears in the scrollpane.
首先感谢楼上的回答。
但是里面的Panel的大小我已经设置好了,拖动滚动条也没有问题。
我要的是拖动内容来实现上下滚动。但是内容拖动成功了,未显示的部分没有刷新出来,拖动条也没有变化。
有没有做过类似项目的大神,求救