我写的测试文件是
import javax.swing.*;
import java.awt.*;
public class wd{
public static void main(String[] args){
JFrame f=new JFrame("window");
String[] s={"呵呵xixihahahah","嘿嘿","我爱你","小宝宝","sdf","sdf","sdf","sdf","sdf","sdf","sdf"};
JScrollPane jsp=new JScrollPane();
JList jl=new JList(s);
jsp.getViewport().add(jl);
f.getContentPane().add(jsp);
f.getContentPane().setLayout(new FlowLayout());
f.setSize(200,300);
f.setVisible(true);
}
}
运行可以看出来,JScrollPane默认是有纵向的滑动条,行条没有纵向的滑动条。
有问题再讨论把
import javax.swing.*;
import java.awt.*;
public class wd{
public static void main(String[] args){
JFrame f=new JFrame("window");
String[] s={"呵呵xixihahahah","嘿嘿","我爱你","小宝宝","sdf","sdf","sdf","sdf","sdf","sdf","sdf"};
JScrollPane jsp=new JScrollPane();
JList jl=new JList(s);
jsp.getViewport().add(jl);
f.getContentPane().add(jsp);
f.getContentPane().setLayout(new FlowLayout());
f.setSize(200,300);
f.setVisible(true);
}
}
运行可以看出来,JScrollPane默认是有纵向的滑动条,行条没有纵向的滑动条。
有问题再讨论把
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);