为什么滚动条对图片不起作用。
      Container contentPane = getContentPane(); 
//加载图片
      canvas = new TransformPanel();
  JScrollPane jsp=new JScrollPane(canvas);
  jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  jsp.setAutoscrolls(true);
      contentPane.add(jsp,"Center");

解决方案 »

  1.   

    import javax.swing.*;public class Test extends JFrame {
        private JPanel pane = null;
        private JScrollPane span = null;    public Test() {
            super("Test");        pane = new JPanel();
            span = new JScrollPane(pane);        pane.add(new JLabel(new ImageIcon("d:/xxx.jpg")));
            //span = new JScrollPane(new JLabel(new ImageIcon("d:/xxx.jpg"))); //或者直接把JLabel加到JScrollPane中也成
            this.getContentPane().add(span);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setSize(300, 200);
            this.setLocationRelativeTo(null);
            this.setVisible(true);
        }    public static void main(String args[]) {
            Test t = new Test();
        }}
      

  2.   

    图片只能放在label里吗??
    那以后就不能编辑啦??
      

  3.   

    也可以直接画到JPanel上,再把JPanel放到JScrollPane中。
      

  4.   

    不起作用啊
          canvas = new TransformPanel();
      JScrollPane jsp=new JScrollPane(canvas);
      jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
          jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      jsp.setAutoscrolls(true);
          contentPane.add(jsp,"Center");