为什么滚动条对图片不起作用。
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");
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");
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();
}}
那以后就不能编辑啦??
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");