import java.awt.Container;
import java.io.File;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class StringBufferDemo{
public static void main(String args[]){
JFrame frame = new JFrame("hehe");
Container con = frame.getContentPane();
String picPath = "d:" + File.separator + "4b66ade8gw1dyizj5ati7j.jpg";
Icon icon = new ImageIcon(picPath);
JPanel pan = new JPanel();
JLabel lab = new JLabel(icon);
pan.add(lab);
JScrollPane jsc = new JScrollPane(pan,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
con.add(jsc);
frame.setSize(200,100);
frame.setVisible(true);
}}
用的是eclipse编写的代码,没有提示一点错误,但是在运行的时候出现如下错误:
Exception in thread "main" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
at javax.swing.JScrollPane.setVerticalScrollBarPolicy(JScrollPane.java:506)
at javax.swing.JScrollPane.<init>(JScrollPane.java:296)
at StringBufferDemo.main(StringBufferDemo.java:21)
请大家指导一下代码应该怎么改? |